The Wayback Machine - https://web.archive.org/web/20240930163254/https://www.geeksforgeeks.org/confidence-interval/
Open In App

Confidence Interval

Last Updated : 21 Dec, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In the realm of statistics, precise estimation is paramount to drawing meaningful insights from data. One of the indispensable tools in this pursuit is the confidence interval. Confidence intervals provide a systematic approach to quantifying the uncertainty associated with sample statistics, offering a range within which population parameters are likely to reside. This article seeks to provide a holistic understanding of confidence intervals and empower readers to wield this statistical tool with confidence in their data analyses.

Prerequisites: t-test, z-test

What is Confidence Interval?

Confidence Interval is a range where we are certain that true value exists. The selection of a confidence level for an interval determines the probability that the confidence interval will contain the true parameter value. This range of values is generally used to deal with population-based data, extracting specific, valuable information with a certain amount of confidence, hence the term ‘Confidence Interval’. 

For example:

If we calculate a 95% confidence interval for a population’s average height, and we randomly select a sample of 50 students and calculate their average height to be 165 cm for instance, and the result is a range of 160 to 170 cm, this suggests that if we were to take multiple samples and create confidence intervals in the same manner, we should anticipate that approximately 95% of those intervals would contain the population’s true average height.

Fig 1: Confidence Interval Illustration

What is Confidence Level?

The confidence level describes the uncertainty associated with a sampling method. 

Suppose we used the same sampling method (say sample mean) to compute a different interval estimate for each sample. Some interval estimates would include the true population parameter, and some would not. 

A 90% confidence level means that we would expect 90% of the interval estimates to include the population parameter. A 95% confidence level means that 95% of the intervals would include the population parameter.

For example:

Let’s suppose you were surveying an average height of men in a particular city. To find that, you set a 95% confidence level and find that the 95% confidence interval is (168,182). That means if you repeated this over and over, 95 percent of the time the height of a man would fall somewhere between 168 cm and 182 cm.

Difference between the Confidence Interval and Confidence Label

Let’s understand the difference between the confidence interval and confidence label.

Aspects

Confidence Interval

Confidence Label

Definition

A confidence interval is a range of values calculated from sample data that is likely to include the true unknown parameter of a population.

The confidence level represents the degree of confidence that the true parameter falls within the calculated confidence interval.

Representation

Numerical range (e.g., [Lower Bound, Upper Bound])

Typically expressed as a percentage (e.g., 95%)

Interpretation

The range within which the true parameter is expected to fall with a certain level of confidence.

The level of confidence in the estimation being made

Example

A 95% confidence interval for the mean height is [65, 70]

We are 95% confident that the true mean height falls within the interval

Steps for Constructing a Confidence Interval

Constructing a confidence interval involves 4 steps:

Step 1: Identify the sample problem. Choose the statistic (like sample mean, etc) that you will use to estimate population parameter.

Clearly define the population parameter you want to estimate and choose an appropriate statistic (e.g., sample mean) to serve as your point estimate.

Step 2: Select a confidence level. (Usually, it is 90%, 95% or 99%)

This reflects the percentage of confidence intervals, derived from random samples, that are expected to contain the true population parameter.

Step 3: Find the margin of error. (Usually given). If not given, use the following formula: –

Margin of error = Criticalvalue * Standard deviation

Finding the critical value

  1. Select Significance Level (Îą): Choose alpha (Îą), typically 0.05, but adjust as needed based on field standards.
  2. Determine Tail Type (One-tailed or Two-tailed): Decide whether a one-tailed or two-tailed interval is appropriate for your analysis. In most cases, a two-tailed interval is used, unless a one-tailed test is specifically required.
  3. Adjust Alpha for Tails: For a two-tailed interval, divide the chosen alpha value by two. This adjustment accounts for both the upper and lower tails of the distribution.
  4. Consult Critical Value Tables: Refer to critical value tables associated with the relevant statistical distribution (e.g., z-table, t-table) to find the critical value corresponding to the adjusted alpha.

Step 4: Specify the confidence interval. The uncertainty is denoted by the confidence level and the range of the confidence interval is defined by Eq-1.

Use the point estimate, along with the margin of error, to define the interval within which you are reasonably confident the population parameter lies. The confidence interval is typically expressed in the form of “point estimate Âą margin of error.”

Confidence \;\; interval = Point\; of \;estimate \;Âą Margin \;of \;error \quad {\cdots (1)}                                                                                      ...(1)

A point estimate is a single value that is used to approximate an unknown population parameter. It is calculated from a sample of data and serves as a best guess for the true parameter value. Common examples of point estimates include the sample mean, sample median, and sample proportion.

Types of Confidence Intervals

Some of the common types of Confidence Intervals are:

  • Confidence Interval for the Mean of Normally Distributed Data
    A confidence interval for the mean of normally distributed data is often calculated using the t-distribution. This interval provides a range within which the true population mean is likely to fall with a specified level of confidence. The formula incorporates the sample mean, standard deviation, and sample size, and the critical value from the t-distribution table adjusts for smaller sample sizes.
  • Confidence Interval for Proportions
    For proportions, a confidence interval estimates the likely range of values for the true population proportion. Typically, the normal approximation or the binomial distribution is used, depending on sample size. The formula involves the sample proportion, standard error, and the critical z-value associated with the chosen confidence level.
  • Confidence Interval for Non-Normally Distributed Data
    When dealing with non-normally distributed data or unknown distributions, bootstrap methods offer a flexible approach. Bootstrap confidence intervals involve resampling from the dataset to create multiple samples, allowing for the estimation of the parameter distribution. This technique is particularly useful when assumptions about the data distribution are uncertain or violated.

Calculating Confidence Interval

Calculation of CI requires two statistical parameters. 

  • Mean (Ξ) — Arithmetic mean is the average of numbers. It is defined as the sum of n numbers divided by the count of numbers till n.
    \mu=\frac{1+2+3+\ldots+n}{n} \quad {\cdots (2)}
  • Standard deviation (σ) — It is the measure of how spread out the numbers are. It is defined as the summation of squared of the difference between each number and the mean.
    \sigma=\sqrt{\sum \frac{\left(x_{i}-\mu\right)^{2}}{n}} \quad {\cdots (3)}
  • Critical Value:
\alpha=\frac{1-C L}{2} \quad {\cdots (4)}

A) Using t-distribution 

We use t-distribution when the sample size n<30. 

Consider the following example. A random sample of 10 UFC fighters was taken and their weights were measured. The mean weight was found to be 240 kg. Construct a 95% confidence interval estimate for the mean weight The sample standard deviation was 25 kg. Find a confidence interval for a sample for the true mean weight of all UFC fighters.

Step 1 – Subtract 1 from your sample size.

This gives the degrees of freedom (df), required in Step-3.

d f=n-1 \quad {...(5)}

where,

  • df = degree of freedom
  • n= sample size

Using Eq-5, we get df = 10 – 1 = 9.

Step 2 – Subtract the confidence interval from 1, then divide by two.

This gives the significance level (Îą), required in Step-3.

\alpha=\frac{1-C L}{2} \quad {...(4)}

  • Îą = Significance level
  • CL = Confidence Level

Using Eq-4, we get Îą = (1 – .95) / 2 = 0.025

Step 3 – Use the values of Îą and df in the t-distribution table and find the value of t.

(df)/(Îą)0.10.050.025. .

∞

1.2821.6451.960. .

1

3.0786.31412.706. .

2

1.8862.9204.303. .

:

:::. .

8

1.3971.8602.306. .

9

1.3831.8332.262. .

Using the values of df and Îą in the t-distribution table, we get t = 2.262.

Step 4 – Use the t-value obtained in step 3 in the formula given for Confidence Interval with t-distribution. [Eq-6]

\mu \pm t\left(\frac{\sigma}{\sqrt{n}}\right) \quad {...(6)}

where,

  • Ξ = mean
  • t = chosen t-value from the table above
  • σ = the standard deviation
  • n = number of observations

So, putting the values in Eq-6, we get

\begin{array}{l} \Rightarrow 240 \pm(2.262)^{*}(25 / \sqrt{10}) \\ \Rightarrow 240 \pm 17.883 \\ \Rightarrow(240-17.883,240+17.883) \\ \Rightarrow(222.117,257.883) \end{array}

where,

  • Lower Limit = 222.117
  • Upper Limit = 257.883

Therefore, we are 95% confident that the true mean weight of the UFC Fighters is between 222.117 and 257.883.

Python implementation

The code uses the ‘scipy.stats’ library module to find the t-value and performs the necessary calculations to obtain the confidence interval. scipy.stats is a subpackage of SciPy, a library in Python for scientific and technical computing. The stats module provides various statistical functions, probability distributions, and statistical tests.

Python3

import scipy.stats as stats
import math
 
# Given values
sample_mean = 240
sample_std_dev = 25
sample_size = 10
confidence_level = 0.95
 
# DF
df = sample_size - 1
 
# Significance level (Îą)
alpha = (1 - confidence_level) / 2
 
# t-value from the t-distribution table
t_value = stats.t.ppf(1 - alpha, df)
 
margin_of_error = t_value * (sample_std_dev / math.sqrt(sample_size))
 
lower_limit = sample_mean - margin_of_error
upper_limit = sample_mean + margin_of_error
 
print(f"Confidence Interval: ({lower_limit}, {upper_limit})")

                    

Output:

Confidence Interval: (222.1160773511857, 257.8839226488143)

B) Using a z-distribution

We use z-distribution when the sample size n>30. Z-test is more useful when the standard deviation is known. 

Consider the following example. A random sample of 50 adult females was taken and their RBC count is measured. The sample mean is 4.63 and the standard deviation of RBC count is 0.54. Construct a 95% confidence interval estimate for the true mean RBC count in adult females.

  • Step 1 – Find the mean. [Eq-2] (If not already given)
  • Step 2 – Find the standard deviation. [Eq-3] (If not already given)
  • Step 3 – Determine the z-value for the specified confidence interval.

(some common values in the table given below)

Confidence Intervalz-value

90%

1.645

95%

1.960

99%

2.576

Step 4 – Use the z-value obtained in step 3 in the formula given for Confidence Interval with z-distribution.

\mu \pm z\left(\frac{\sigma}{\sqrt{n}}\right) \quad {\cdots (7)}

where,

  • Ξ = mean
  • z = chosen z-value from the table above
  • σ = the standard deviation
  • n = number of observations

Putting the values in Eq-7, we get

\begin{array}{l} \Rightarrow4.63 \pm(1.960)^{*}(0.54 / \sqrt{50}) \\ \Rightarrow 4.63 \pm 0.149 \\ \Rightarrow(4.63-0.149,4.63+0.149) \\ \Rightarrow(4.480,4.780) \end{array}

where,

  • Lower Limit = 4.480
  • Upper Limit = 4.780

Therefore, we are 95% confident that the true mean RBC count of adult females is between 4.480 and 4.780.

Python Implementation

Python3

from scipy import stats
import numpy as np
 
sample_mean = 4.63
std_dev = 0.54
sample_size = 50
confidence_level = 0.95
 
# Standard error
standard_error = std_dev / np.sqrt(sample_size)
 
# z-value for specified confidence interval
z_value = 1.960  # Taken from table for a 95% confidence interval
 
margin_of_error = z_value * (std_dev / math.sqrt(sample_size))
 
lower_limit = sample_mean - margin_of_error
upper_limit = sample_mean + margin_of_error
 
print(f"Confidence Interval: ({lower_limit:.3f}, {upper_limit:.3f})")

                    

Output:

Confidence Interval: (4.480, 4.780)

Factors influencing Confidence Interval

The width of a confidence interval is primarily influenced by three factors:

  1. Sample Size (n): Larger sample sizes tend to result in narrower confidence intervals because they provide more precise estimates of the population parameter.
  2. Variability in the Data (Standard Deviation or Standard Error): Greater variability in the data leads to wider confidence intervals, as there is more uncertainty in the estimates.
  3. Confidence Level (CL): Higher confidence levels, such as 95% or 99%, result in wider intervals. This reflects the trade-off between precision and confidence – higher confidence requires a wider range.

When do you use confidence intervals?

Confidence intervals are an essential tool for determining the range that a population parameter, like a mean or proportion, is most likely to fall into.

  1. These intervals give important information about the dependability of study findings and provide a measure of uncertainty around a point estimate.
  2. Confidence intervals help researchers express the accuracy of their estimates and make stronger conclusions when working with sample data.
  3. Confidence intervals, in essence, give a reasonable range for the true population parameter while acknowledging the inherent variability in data.
  4. Confidence intervals are frequently used by researchers in hypothesis testing so they can determine whether a given value falls within the interval and thus influence conclusions about the statistical significance of the data.
  5. Whether in medical research, social sciences, or business analytics, the judicious use of confidence intervals enhances the credibility and depth of statistical inferences, fostering a nuanced understanding of the underlying phenomena.

Conclusion

Confidence Interval is one of the foundational concepts of statistics. It tells a statement about the data. Various sampling methods such as mean, median etc. can be used based on the data present. One can also determine what distribution to use when in order to get the best results. For any doubts/queries, comment below.

Frequently Asked Questions (FAQs)

1. What is the 95% confidence interval rule?

The 95% confidence interval rule states that if we repeatedly construct 95% confidence intervals for a population parameter, we can expect 95% of those intervals to contain the true parameter value.

2. What if 95 confidence interval includes 1?

If the 95% confidence interval includes 1, it means that we are not statistically confident in saying that the true parameter value is different from 1. In other words, the data is not strong enough to rule out the possibility that the true parameter value is 1.

3. What is the difference between confidence level and confidence interval?

The confidence level is the probability that the confidence interval contains the true parameter value. The confidence interval is a range of values that is likely to contain the true parameter value.

4. How to find sample size?

The sample size is the number of observations in a sample. The sample size is determined by the desired confidence level, the desired margin of error, and the variability of the data.

5. What is the 5 significance level?

The significance level is the probability of rejecting the null hypothesis when it is actually true. The significance level is typically set at 0.05, which means that we are willing to accept a 5% chance of making a Type I error.




Previous Article
Next Article

Similar Reads

How to calculate the 95% confidence interval for the slope in a linear regression model in R
Linear regression is a fundamental statistical technique used to model the relationship between a dependent variable (response) and one or more independent variables (predictors). When interpreting the results of a linear regression model, understanding the uncertainty around the estimated coefficients is crucial. One way to quantify this uncertain
4 min read
Confidence interval for xgboost regression in R
XGBoost is Designed to be highly efficient, versatile, and portable, it is an optimized distributed gradient boosting library. Under the Gradient Boosting framework, it puts machine learning techniques into practice. Many data science problems can be swiftly and precisely resolved with XGBoost's parallel tree boosting, also referred to as GBDT or G
4 min read
Upper Confidence Bound Algorithm in Reinforcement Learning
In Reinforcement learning, the agent or decision-maker generates its training data by interacting with the world. The agent must learn the consequences of its actions through trial and error, rather than being explicitly told the correct action. Multi-Armed Bandit Problem In Reinforcement Learning, we use Multi-Armed Bandit Problem to formalize the
6 min read
Confidence Intervals for Machine Learning
In machine learning, confidence intervals play a crucial role in quantifying the uncertainty associated with model predictions and parameter estimates. They provide a range of values within which we can be confident that the true value lies, given a certain level of probability. In this article, we will see confidence intervals relevance in Machine
8 min read
Confidence Intervals for XGBoost
Confidence intervals provide a range within which we expect the true value of a parameter to lie, with a certain level of confidence. In the context of XGBoost, confidence intervals can be used to quantify the uncertainty of predictions. In this article we explain how to compute confidence intervals for predictions made by an XGBoost model. What ar
4 min read
Confidence Intervals for Caret Package in R
Confidence intervals are an essential aspect of statistical analysis, providing a range of values within which we can expect the true parameter to lie, with a certain level of confidence. In predictive modeling, confidence intervals help us understand the uncertainty around our model estimates. The caret package in R is a powerful tool for building
4 min read
Confidence and Prediction Intervals with Statsmodels
In statistical analysis, particularly in linear regression, understanding the uncertainty associated with predictions is crucial. Confidence intervals and prediction intervals are two essential tools for quantifying this uncertainty. Confidence intervals provide a range within which the mean of the population is likely to lie, while prediction inte
5 min read
Adding 95% Confidence Intervals to Line Charts in Plotly
Creating a line chart with a 95% confidence interval (CI) in Plotly is a powerful way to visualize data with uncertainty. Confidence intervals provide a range of values that likely contain the true value of the parameter being measured, thus adding a layer of statistical insight to your visualizations. This article will guide you through the proces
4 min read
Program for class interval arithmetic mean
Given a class interval and frequency distribution and the task is to find Arithmetic mean. In case of frequency distribution the raw data is arranged by intervals having corresponding frequencies. So if we are interested to find arithmetic mean of the data having class interval we must know the mid variable x. This variable can be calculated by usi
7 min read
Largest interval in an Array that contains the given element X for Q queries
Given an array arr[] of N elements and Q queries of the form [X]. For each query, the task is to find the largest interval [L, R] of the array such that the greatest element in the interval is arr[X], such that 1 ? L ? X ? R. Note: The array has 1-based indexing. Examples: Input: N = 5, arr[] = {2, 1, 2, 3, 2}, Q = 3, query[] = {1, 2, 4} Output: [1
10 min read
Sum of Interval and Update with Number of Divisors
Given an array A of N integers. You have to answer two types of queries : 1. Update [l, r] - for every i in range from l to r update Ai with D(Ai), where D(Ai) represents the number of divisors of Ai 2. Query [l, r] - calculate the sum of all numbers ranging between l and r in array A. Input is given as two integers N and Q, representing number of
12 min read
Find the largest interval that contains exactly one of the given N integers.
Given an array arr[] of N distinct integers, the task is to find the maximum element in an interval [L, R] such that the interval contains exactly one of the given N integers and 1 ? L ? R ? 105 Input: arr[] = {5, 10, 200} Output: 99990 All possible intervals are [1, 9], [6, 199] and [11, 100000]. [11, 100000] has the maximum integers i.e. 99990.In
5 min read
Maximum points covered after removing an Interval
Given N intervals in the form [l, r] and an integer Q. The task is to find the interval which when removed results in the coverage of the maximum number of points (Union of all the rest of the intervals). Note that all the given intervals cover numbers between 1 to Q only. Examples: Input: intervals[][] = {{1, 4}, {4, 5}, {5, 6}, {6, 7}, {3, 5}}, Q
9 min read
Count of available non-overlapping intervals to be inserted to make interval [0, R]
Given an integer R which signifies the range [0, R] and two arrays start[] and end[] of size N which signifies the starting and ending intervals in the range [0, R]. The task is to count the number of available non-overlapping intervals which need to be inserted in the arrays such that on merging the individual ranges in the arrays start[] and end[
13 min read
Distance traveled by Hour and Minute hand in given Time interval
Given two numbers H and M which denotes the length of the hour and minute hand and two time intervals(say T1 & T2) in form of HH:MM, the task is to find the distance traveled by hour hand and minute hand between time T1 and T2. Examples: Input: H = 5, M = 7, T1 = "1:30", T2 = "10:50" Output: Distance travelled by minute hand: 410.50144006906635
10 min read
Print a pair of indices of an overlapping interval from given array
Given a 2D array arr[][] of size N, with each row representing intervals of the form {X, Y} ( 1-based indexing ), the task to find a pair of indices of overlapping intervals. If no such pair exists, then print -1 -1. Examples: Input: N = 5, arr[][] = {{1, 5}, {2, 10}, {3, 10}, {2, 2}, {2, 15}}Output: 4 1Explanation: The range at position 4 i.e., (2
12 min read
Minimum removals required to make any interval equal to the union of the given Set
Given a set S of size N (1 ? N ? 1e5) consisting of intervals, the task is to find the minimum intervals required to be removed from the set such that any one of the remaining intervals becomes equal to the union of this set. Examples: Input: S = {[1, 3], [4, 12], [5, 8], [13, 20]}Output: 2Explanation: Removing the intervals [1, 3] and [13, 20] mod
7 min read
Maximum number of intervals that an interval can intersect
Given an array arr[] consisting of N intervals of the form of [L, R], where L, R denotes the start and end positions of the interval, the task is to count the maximum number of intervals that an interval can intersect with each other. Examples: Input: arr[] = {{1, 2}, {3, 4}, {2, 5}}Output: 3Explanation: The required set of intervals are {1, 2}, {2
15+ min read
Total time to pick elements with given time interval
Given an array arr[] of size N that denotes the type of an element, and another time array time[] of size N where time[i] denotes the time interval between picking two elements of the ith type. The task is to find the time taken to pick all the elements while traversing from left to right of the array. Note: Moving between adjacent positions takes
6 min read
Maximum sum of at most two non-overlapping intervals in a list of Intervals | Interval Scheduling Problem
Given an array interval of length N, where each element represents three values, i.e. {startTime, endTime, value}. The task is to find the maximum sum of values of at most two non-overlapping intervals. Example: Input: interval[] = [[1, 3, 2], [4, 5, 2], [2, 4, 3]]Output: 4Explanation: Select interval 1 and 2 (as third interval is overlapping). The
7 min read
Find index of closest non-overlapping interval to right of each of given N intervals
Given an array arr[] of N intervals, the task is to calculate the index of the closest interval to the right of each of the given N intervals that do not overlap with the current interval. Examples: Input: arr[] = {{3, 4}, {2, 3}, {1, 2}}Output: -1 0 1Explanation: For the interval arr[0], there exists no interval to the right of it. For interval ar
7 min read
Add minimum sized interval such that all intervals merge into one
Given a 2D array arr of size N which represents an interval [start, end] inclusive where (start < end), the task is to add only one interval of minimum size (size = end - start) into the given arr, such that merging all the interval result in only one interval. Examples: Input: arr= {{12, 20}, {24, 100}}Output: 4Explanation: We can add the inter
8 min read
Max length of common interval whose Bitwise OR, AND are equal in both Arrays
Given two arrays A and B of length N, find the maximum length of a common interval of A and B such that the bitwise OR of the elements in the interval of A is equal to the bitwise AND of the elements in the interval of B. Formally, given the indices i and j (0 ? i ? j < N), find the maximum value of j-i+1 such that: (A[i] OR A[i+1] OR ... OR A[j
14 min read
Minimum number of intervals to cover the target interval
Given an array A[] consisting of N intervals and a target interval X, the task is to find the minimum number of intervals from the given array A[] such that they entirely cover the target interval. If there doesn't exist any such interval then print "-1". Examples: Input: A[] = {{1, 3}, {2, 4}, {2, 10}, {2, 3}, {1, 1}}, X = {1, 10}Output: 2Explanat
15+ min read
Find the interval which contains maximum number of concurrent meetings
Given a two-dimensional array arr[][] of dimensions N * 2 which contains the starting and ending time for N meetings on a given day. The task is to print a list of time slots during which the most number of concurrent meetings can be held. Examples: Input: arr[][] = {{100, 300}, {145, 215}, {200, 230}, {215, 300}, {215, 400}, {500, 600}, {600, 700}
7 min read
Interval Tree
Consider a situation where we have a set of intervals and we need following operations to be implemented efficiently. 1) Add an interval 2) Remove an interval 3) Given an interval x, find if x overlaps with any of the existing intervals.Interval Tree: The idea is to augment a self-balancing Binary Search Tree (BST) like Red Black Tree, AVL Tree, et
15+ min read
Remove Interval from Disjoint Intervals
Given a sorted list of disjoint intervals representing a set of real numbers and an interval toBeRemoved to remove. The task is to remove toBeRemoved interval from the set and return the remaining intervals as a sorted list. Example: Input: intervals = {{0,2},{3,4},{5,7}}, toBeRemoved = {1,6}Output: {{0,1},{6,7}} Input: intervals = {{0,5}}, toBeRem
7 min read
Maximum occurring divisor in an interval
Given an interval [x, y], the task is to find the divisor that occurs maximum number of times except '1' in the divisors of numbers in the range [x, y], both inclusive. Examples : Input : [2, 5]Output : 2Explanation : Divisors of 2, 3, 4, 5 except 1 are: 2 -> 2 3 -> 3 4 -> 2, 4 5 -> 5 Among all the divisors 2 occurs maximum time, i.e tw
11 min read
Check if any interval completely overlaps the other
An interval is represented as a combination of start time and end time. Given a set of intervals, we need to write a program to check if any interval completely overlaps the other. Examples: Input: arr[] = {{1, 3}, {1, 7}, {4, 8}, {2, 5}}Output: trueExplanation: The intervals {1, 3} completely overlaps in {1, 7}. Input: arr[] = {{1, 3}, {7, 9}, {4,
13 min read
Insert in sorted and non-overlapping interval array
Given a set of non-overlapping intervals and a new interval, insert the interval at the correct position. If the insertion results in overlapping intervals, then merge the overlapping intervals. Assume that the set of non-overlapping intervals is sorted based on start time, to find the correct position of insertion. Prerequisite: Merge the interval
15+ min read