Adding sample size to a box plot at the min or max of the facet in ggplot

There are plenty of explanations, including this good one, of how to label box plots with sample size. All of them seem to use max(x) or median(x) to position the sample size. I'm wondering if there is a way to easily position the labels at the top or bottom of the plot, especially when using the scale = "free_y" command in facet where the max and minimum value for the axis is picked automatically for each facet by ggplot. The reason is that I am creating multiple facets where the distributions are narrow and the facets are small. It would be easier to read the sample size if it were positioned at the top or bottom of the plot. but I'd like to use "free_y" because there are meaningful differences in some facets that are obscured by the facets that have much larger spans in the data. Using a slightly modified example from the linked post:

# function for number of observations give.n # function for mean labels mean.n # plot ggplot(mtcars, aes(factor(cyl), mpg, label=rownames(mtcars))) + geom_boxplot(fill = "grey80", colour = "#3366FF") + stat_summary(fun.data = give.n, geom = "text", fun.y = median) + stat_summary(fun.data = mean.n, geom = "text", fun.y = mean, colour = "red") + facet_grid(cyl~., scale="free_y") 

Given this setup, how could I find the min or max of the x axis for each facet and position the sample size there instead of at the median, min or max of each box-and-whisker? EDIT I'm updating the question with information from R.S.'s answer below. It's still not answered yet, but their suggestion provides a solution for where to find this information.

ggplot_build(gg)$layout$panel_ranges[[order(levels(factor(mtcars$cyl)))[1]]]$y.range[1] 

gives the minimum of the y range for the first factor of mtcars$cyl. So, by my logic, we need to build the plot, without the stat_summary statements, then find the sample size and minimum y-range using the give.n function. After that, we can add the stat_summary statement to the plot. like below:

# plot gg = ggplot(mtcars, aes(factor(cyl), mpg, label=rownames(mtcars))) + geom_boxplot(fill = "grey80", colour = "#3366FF") + facet_grid(cyl~., scale="free_y") # function for number of observations give.n gg + stat_summary(fun.data = give.n, geom = "text", fun.y = "median") 

enter image description here

But. the above code doesn't work because I don't really understand what the give.n function is iterating over. Replacing [[x]] with any of 1:3 plots all the sample sizes at the minimum for that facet, so that is progress. Here is the plot using [[2]] , so all sample sizes are plotted at 17.62, the minimum value of the range for the second facet.