The Wayback Machine - https://web.archive.org/web/20240823161812/https://www.geeksforgeeks.org/find-minimum-radius-atleast-k-point-lie-inside-circle/
Open In App

Find minimum radius such that atleast k point lie inside the circle

Last Updated : 02 Oct, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow
Solve Problem
Easy
51.59%
3K

Given a positive integer K, a circle center at (0, 0) and coordinates of some points. The task is to find minimum radius of the circle so that at-least k points lie inside the circle. Output the square of the minimum radius. 

Examples:  

Input : (1, 1), (-1, -1), (1, -1), 
k = 3
Output : 2
We need a circle of radius at least 2
to include 3 points.
Input : (1, 1), (0, 1), (1, -1),
k = 2
Output : 1
We need a circle of radius at least 1
to include 2 points. The circle around
(0, 0) of radius 1 would include (1, 1)
and (0, 1).

The idea is to find square of Euclidean Distance of each point from origin (0, 0). Now, sort these distance in increasing order. Now the kth element of distance is the required minimum radius.
Below is the implementation of this approach: 

C++




// C++ program to find minimum radius
// such that atleast k point lie inside
// the circle
#include<bits/stdc++.h>
using namespace std;
 
// Return minimum distance required so that
// atleast k point lie inside the circle.
int minRadius(int k, int x[], int y[], int n)
{
   int dis[n];
     
   // Finding distance between of each
   // point from origin
   for (int i = 0; i < n; i++)
       dis[i] = x[i] * x[i] + y[i] * y[i];
     
    // Sorting the distance
    sort(dis, dis + n);
     
    return dis[k - 1];
}
 
// Driven Program
int main()
{
  int k = 3;
  int x[] = { 1, -1, 1 };
  int y[] = { 1, -1, -1 };
  int n = sizeof(x)/sizeof(x[0]);
     
  cout << minRadius(k, x, y, n) << endl;
     
  return 0;
}


Java




// Java program to find minimum radius
// such that atleast k point lie inside
// the circle
import java.util.Arrays;
 
class GFG
{
 
    // Return minimum distance required so that
    // atleast k point lie inside the circle.
    static int minRadius(int k, int[] x, int[] y,
                                          int n)
    {
        int[] dis=new int[n];
     
        // Finding distance between of each
        // point from origin
        for (int i = 0; i < n; i++)
            dis[i] = x[i] * x[i] + y[i] * y[i];
     
        // Sorting the distance
        Arrays.sort(dis);
     
        return dis[k - 1];
    }
 
    // Driven Program
    public static void main (String[] args) {
         
    int k = 3;
    int[] x = { 1, -1, 1 };
    int[] y = { 1, -1, -1 };
    int n = x.length;
     
    System.out.println(minRadius(k, x, y, n));
 
    }
}
 
/* This code is contributed by Mr. Somesh Awasthi */


Python3




# Python3 program to find minimum radius
# such that atleast k point lie inside
# the circle
 
 
# Return minimum distance required so
# that atleast k point lie inside the
# circle.
def minRadius(k, x, y, n):
    dis = [0] * n
 
    # Finding distance between of each
    # point from origin
 
    for i in range(0, n):
        dis[i] = x[i] * x[i] + y[i] * y[i]
 
    # Sorting the distance
    dis.sort()
 
    return dis[k - 1]
         
# Driver Program
k = 3
x = [1, -1, 1]
y = [1, -1, -1]
n = len(x)
 
print(minRadius(k, x, y, n))
 
# This code is contributed by
# Prasad Kshirsagar


C#




// C# program to find minimum radius
// such that atleast k point lie inside
// the circle
using System;
 
class GFG {
 
    // Return minimum distance required
    // so that atleast k point lie inside
    // the circle.
    static int minRadius(int k, int []x,
                          int[] y, int n)
    {
        int[] dis = new int[n];
     
        // Finding distance between of
        // each point from origin
        for (int i = 0; i < n; i++)
            dis[i] = x[i] * x[i] +
                       y[i] * y[i];
     
        // Sorting the distance
        Array.Sort(dis);
     
        return dis[k - 1];
    }
 
    // Driven Program
    public static void Main ()
    {
        int k = 3;
        int[] x = { 1, -1, 1 };
        int[] y = { 1, -1, -1 };
        int n = x.Length;
         
        Console.WriteLine(
              minRadius(k, x, y, n));
    }
}
 
// This code is contributed by vt_m.


Javascript





PHP




<?php
// PHP program to find minimum radius
// such that atleast k point lie inside
// the circle
 
// Return minimum distance required
// so that atleast k point lie
// inside the circle.
function minRadius($k, $x, $y, $n)
{
    $dis =array();
         
    // Finding distance between
    // of each point from origin
    for ($i = 0; $i < $n; $i++)
        $dis[$i] = $x[$i] * $x[$i] +
                   $y[$i] * $y[$i];
         
        // Sorting the distance
        sort($dis);
         
        return $dis[$k - 1];
}
 
// Driver Code
$k = 3;
$x = array(1, -1, 1);
$y = array(1, -1, -1);
$n = count($x);
     
echo minRadius($k, $x, $y, $n) ;
     
// This code is contributed by anuj_67.
?>


Output

2

Time complexity: O(n + nlogn)
Auxiliary Space: O(n)ve.

Approach#2: Using binary search

This code uses binary search to find the minimum radius such that at least k points lie inside or on the circumference of the circle. It first finds the maximum distance between any two points, then performs binary search on the range [0, max_distance] to find the minimum radius.

Algorithm

1. Initialize left = 0 and right = maximum distance between any two points in the given set of points.
2. While left <= right, find mid = (left + right) / 2
3. Check if there exist k points inside or on the circumference of a circle with radius mid using a simple linear search. 4. If k or more points are inside or on the circumference of the circle, set right = mid – 1.
5. If less than k points are inside or on the circumference of the circle, set left = mid + 1.
6. After the binary search, the value of left will be the minimum radius required to include k points.

C++




#include <cmath>
#include <iostream>
#include <vector>
 
using namespace std;
 
double dist(pair<int, int> p1, pair<int, int> p2)
{
    // Calculate Euclidean distance between two points
    return sqrt(pow(p1.first - p2.first, 2)
                + pow(p1.second - p2.second, 2));
}
 
int count_points_in_circle(vector<pair<int, int> > points,
                           pair<int, int> center,
                           double radius)
{
    // Count the number of points inside or on the
    // circumference of the circle
    int count = 0;
    for (auto point : points) {
        if (dist(point, center) <= radius) {
            count++;
        }
    }
    return count;
}
 
int MinimumRadius(vector<pair<int, int> > points, int k)
{
    double left = 0.0;
    double right = 0.0;
    // Find the maximum distance between any two points
    for (int i = 0; i < points.size(); i++) {
        for (int j = i + 1; j < points.size(); j++) {
            double d = dist(points[i], points[j]);
            if (d > right) {
                right = d;
            }
        }
    }
    while (left <= right) {
        double mid = (left + right) / 2.0;
        bool found = false;
        // Check if there exist k points inside or on the
        // circumference of a circle with radius mid
        for (int i = 0; i < points.size(); i++) {
            if (count_points_in_circle(points, points[i],
                                       mid)
                >= k) {
                found = true;
                break;
            }
        }
        if (found) {
            right = mid - 1.0;
        }
        else {
            left = mid + 1.0;
        }
    }
    return static_cast<int>(left);
}
 
// Example usage
int main()
{
    vector<pair<int, int> > points{ { 1, 1 },
                                    { -1, -1 },
                                    { 1, -1 } };
    int k = 3;
    cout << MinimumRadius(points, k) << endl;
}


Java




import java.util.ArrayList;
 
public class MinimumRadiusProblem {
 
    public static double dist(double[] p1, double[] p2) {
        // Calculate Euclidean distance between two points
        return Math.sqrt(Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2));
    }
 
    public static int count_points_in_circle(ArrayList<double[]> points, double[] center, double radius) {
        // Count the number of points inside or on the circumference of the circle
        int count = 0;
        for (double[] point : points) {
            if (dist(point, center) <= radius) {
                count++;
            }
        }
        return count;
    }
 
    public static int minimumRadius(ArrayList<double[]> points, int k) {
        double left = 0.0;
        double right = 0.0;
        // Find the maximum distance between any two points
        for (int i = 0; i < points.size(); i++) {
            for (int j = i + 1; j < points.size(); j++) {
                double d = dist(points.get(i), points.get(j));
                if (d > right) {
                    right = d;
                }
            }
        }
        while (left <= right) {
            double mid = (left + right) / 2.0;
            boolean found = false;
            // Check if there exist k points inside or on the circumference of a circle with radius mid
            for (double[] point : points) {
                if (count_points_in_circle(points, point, mid) >= k) {
                    found = true;
                    break;
                }
            }
            if (found) {
                right = mid - 1.0;
            } else {
                left = mid + 1.0;
            }
        }
        return (int) Math.floor(left);
    }
 
    // Example usage
    public static void main(String[] args) {
        ArrayList<double[]> points = new ArrayList<>();
        points.add(new double[]{1, 1});
        points.add(new double[]{-1, -1});
        points.add(new double[]{1, -1});
 
        int k = 3;
        System.out.println(minimumRadius(points, k));
    }
}


Python3




import math
 
def dist(p1, p2):
    # Calculate Euclidean distance between two points
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
 
def count_points_in_circle(points, center, radius):
    # Count the number of points inside or on the circumference of the circle
    count = 0
    for point in points:
        if dist(point, center) <= radius:
            count += 1
    return count
 
def minimum_radius(points, k):
    left, right = 0, 0
    # Find the maximum distance between any two points
    for i in range(len(points)):
        for j in range(i+1, len(points)):
            d = dist(points[i], points[j])
            if d > right:
                right = d
    while left <= right:
        mid = (left + right) / 2
        found = False
        # Check if there exist k points inside or on the circumference of a circle with radius mid
        for i in range(len(points)):
            if count_points_in_circle(points, points[i], mid) >= k:
                found = True
                break
        if found:
            right = mid - 1
        else:
            left = mid + 1
    return int(left)
 
# Example usage
points = [(1, 1), (-1, -1), (1, -1)]
k = 3
print(minimum_radius(points, k))


C#




using System;
using System.Collections.Generic;
 
public class MinimumRadiusProblem
{
    public static double dist(double[] p1, double[] p2)
    {
        // Calculate Euclidean distance between two points
        return Math.Sqrt(Math.Pow(p1[0] - p2[0], 2) + Math.Pow(p1[1] - p2[1], 2));
    }
 
    public static int count_points_in_circle(List<double[]> points, double[] center, double radius)
    {
        // Count the number of points inside or on the circumference of the circle
        int count = 0;
        foreach (double[] point in points)
        {
            if (dist(point, center) <= radius)
            {
                count++;
            }
        }
        return count;
    }
 
    public static int minimumRadius(List<double[]> points, int k)
    {
        double left = 0.0;
        double right = 0.0;
        // Find the maximum distance between any two points
        for (int i = 0; i < points.Count; i++)
        {
            for (int j = i + 1; j < points.Count; j++)
            {
                double d = dist(points[i], points[j]);
                if (d > right)
                {
                    right = d;
                }
            }
        }
        while (left <= right)
        {
            double mid = (left + right) / 2.0;
            bool found = false;
            // Check if there exist k points inside or on the circumference of a circle with radius mid
            foreach (double[] point in points)
            {
                if (count_points_in_circle(points, point, mid) >= k)
                {
                    found = true;
                    break;
                }
            }
            if (found)
            {
                right = mid - 1.0;
            }
            else
            {
                left = mid + 1.0;
            }
        }
        return (int)Math.Floor(left);
    }
 
    // Example usage
    public static void Main(string[] args)
    {
        List<double[]> points = new List<double[]>
        {
            new double[] { 1, 1 },
            new double[] { -1, -1 },
            new double[] { 1, -1 }
        };
 
        int k = 3;
        Console.WriteLine(minimumRadius(points, k));
    }
}


Javascript




// JavaScript implementation of Minimum Radius problem
function dist(p1, p2) {
    // Calculate Euclidean distance between two points
    return Math.sqrt(Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2));
}
 
function count_points_in_circle(points, center, radius) {
    // Count the number of points inside or on the
    // circumference of the circle
    let count = 0;
    for (let point of points) {
        if (dist(point, center) <= radius) {
            count++;
        }
    }
    return count;
}
 
function MinimumRadius(points, k) {
    let left = 0.0;
    let right = 0.0;
    // Find the maximum distance between any two points
    for (let i = 0; i < points.length; i++) {
        for (let j = i + 1; j < points.length; j++) {
            let d = dist(points[i], points[j]);
            if (d > right) {
                right = d;
            }
        }
    }
    while (left <= right) {
        let mid = (left + right) / 2.0;
        let found = false;
        // Check if there exist k points inside or on the
        // circumference of a circle with radius mid
        for (let i = 0; i < points.length; i++) {
            if (count_points_in_circle(points, points[i], mid) >= k) {
                found = true;
                break;
            }
        }
        if (found) {
            right = mid - 1.0;
        } else {
            left = mid + 1.0;
        }
    }
    return Math.floor(left);
}
 
// Example usage
const points = [
    [1, 1],
    [-1, -1],
    [1, -1]
];
const k = 3;
console.log(MinimumRadius(points, k));


Output

2

Time Complexity: O(n^2 * log(r)) where n is the number of points and r is the maximum distance between any two points.
Space complexity: O(1) as it uses only a constant amount of extra space irrespective of the size of the input.


Please write comments if you find anything incorrect, or you want to share more information about the topic discussed abo



Similar Reads

Radii of the three tangent circles of equal radius which are inscribed within a circle of given radius
Given here is a circle of a given radius. Inside it, three tangent circles of equal radius are inscribed. The task is to find the radii of these tangent circles. Examples: Input: R = 4Output: 1.858 Input: R = 11Output: 5.1095 Approach: Let the radii of the tangent circles be r, and the radius of the circumscribing circle is R.x is the smaller dista
3 min read
Queries on count of points lie inside a circle
Given n coordinate (x, y) of points on 2D plane and Q queries. Each query contains an integer r, the task is to count the number of points lying inside or on the circumference of the circle having radius r and centered at the origin.Examples : Input : n = 5 Coordinates: 1 1 2 2 3 3 -1 -1 4 4 Query 1: 3 Query 2: 32 Output : 3 5 For first query radiu
8 min read
Find area of the larger circle when radius of the smaller circle and difference in the area is given
Given two integers r and d where r is the radius of the smaller circle and d is the difference of the area of this circle with some larger radius circle. The task is to find the area of the larger circle.Examples: Input: r = 4, d = 5 Output: 55.24 Area of the smaller circle = 3.14 * 4 * 4 = 50.24 55.24 - 50.24 = 5Input: r = 12, d = 3 Output: 455.16
4 min read
Find if a point lies inside a Circle
Given a circle (coordinates of centre and radius) and a point (coordinate), find if the point lies inside or on the circle, or not. Examples : Input: x = 4, y = 4 // Given Point circle_x = 1, circle_y = 1, rad = 6; // Circle Output: Inside Input: x = 3, y = 3 // Given Point circle_x = 0, circle_y = 1, rad = 2; // Circle Output: Outside We strongly
5 min read
Coordinates of rectangle with given points lie inside
Given two arrays X[] and Y[] with n-elements, where (Xi, Yi) represent a point on coordinate system, find the smallest rectangle such that all points from given input lie inside that rectangle and sides of rectangle must be parallel to Coordinate axis. Print all four coordinates of an obtained rectangle. Note: n &gt;= 4 (we have at least 4 points a
6 min read
Check if a circle lies inside another circle or not
Given two circles with radii and centres given. The task is to check whether the smaller circle lies inside the bigger circle or not.  Examples:   Input: x1 = 10, y1 = 8, x2 = 1, y2 = 2, r1 = 30, r2 = 10 Output: The smaller circle lies completely inside the bigger circle without touching each other at a point of circumference. Input :x1 = 7, y1 = 8
6 min read
Find the number of points that have atleast 1 point above, below, left or right of it
Given N points in a 2-dimensional plane. A point is said to be above another point if the X coordinates of both points are same and the Y coordinate of the first point is greater than the Y coordinate of the second point. Similarly, we define below, left and right. The task is to count the number of points that have atleast one point above, below,
8 min read
Find the radius of the circles which are lined in a row, and distance between the centers of first and last circle is given
Given here are n circles which touch each other externally, and are lined up in a row. The distance between the centers of the first and last circle is given. The circles have a radius of equal length. The task is to find the radius of each circle. Examples: Input: d = 42, n = 4 Output: The radius of each circle is 7 Input: d = 64, n = 5 Output: Th
3 min read
Find pairs with given sum such that pair elements lie in different BSTs
Given two Binary Search Trees (BST) and a given sum. The task is to find pairs with given sum such that each pair elements must lie in different BST. Examples: Input : sum = 10 8 5 / \ / \ 3 10 2 18 / \ \ / \ 1 6 14 1 3 / \ / \ 5 7 13 4 Output : (5,5), (6,4), (7,3), (8,2) In above pairs first element lies in first BST and second element lies in sec
14 min read
Minimum K such that every substring of length atleast K contains a character c
Given a string S containing lowercase latin letters. A character c is called K-amazing if every substring of S with length atleast K contains this character c. Find the minimum possible K such that there exists atleast one K-amazing character. Examples: Input : S = "abcde" Output :3 Explanation : Every substring of length atleast 3 contains charact
11 min read
Choose atleast two elements from array such that their GCD is 1 and cost is minimum
Given two integer arrays arr[] and cost[] where cost[i] is the cost of choosing arr[i]. The task is to choose a subset with at least two elements such that the GCD of all the elements from the subset is 1 and the cost of choosing those elements is as minimum as possible then print the minimum cost. Examples: Input: arr[] = {5, 10, 12, 1}, cost[] =
6 min read
Sum of area of alternative concentric circle with radius 1,2,3,4..........N
Given that Concentric circle of radii 1,2,3,4..........N cm are drawn. The interior of the smallest circle is colored white and angular regions are colored alternately green and white so that no two adjacent regions are of the same color. The task is to find the total area of the green region in sq cm. Examples: Input: N=100Output: 15865.0429006284
5 min read
Radius of the biggest possible circle inscribed in rhombus which in turn is inscribed in a rectangle
Give a rectangle with length l &amp; breadth b, which inscribes a rhombus, which in turn inscribes a circle. The task is to find the radius of this circle.Examples: Input: l = 5, b = 3 Output: 1.28624 Input: l = 6, b = 4 Output: 1.6641 Approach: From the figure, it is clear that diagonals, x &amp; y, are equal to the length and breadth of the recta
4 min read
Equation of circle from center and radius
Given the center of circle (x1, y1) and its radius r, find the equation of the circle having center (x1, y1) and having radius r.Examples: Input : x1 = 2, y1 = -3, r = 8 Output : x^2 + y^2 - 4*x + 6*y = 51.Input : x1 = 0, y1 = 0, r = 2 Output : x^2 + y^2 - 0*x + 0*y = 4. Approach: Given the center of circle (x1, y1) and its radius r, we have to fin
5 min read
Length of the chord of the circle whose radius and the angle subtended at the center by the chord is given
Given a circle whose radius and the angle subtended at the centre by its chord is given. The task is to find the length of the chord.Examples: Input: r = 4, x = 63 Output: 4.17809 Input:: r = 9, x = 71 Output:: 10.448 Approach: Let the circle has center at O and has radius r, and it's chord be AB.length of the chord be 2d, and the angle subtended b
4 min read
Radius of the circle when the width and height of an arc is given
Given a circle in which the width and height of an arc are given. The task is to find the radius of the circle with the help of the width and height of the arc.Examples: Input: d = 4, h = 1 Output: The radius of the circle is 2.5 Input: d = 14, h = 8 Output: The radius of the circle is 7.0625 Approach Let the radius of the circle be rLet the height
4 min read
Area of Equilateral triangle inscribed in a Circle of radius R
Given an integer R which denotes the radius of a circle, the task is to find the area of an equilateral triangle inscribed in this circle. Examples: Input: R = 4 Output: 20.784 Explanation: Area of equilateral triangle inscribed in a circle of radius R will be 20.784, whereas side of the triangle will be 6.928 Input: R = 7 Output: 63.651 Explanatio
4 min read
Radius of a circle having area equal to the sum of area of the circles having given radii
Given two integers r1 and r2, representing the radius of two circles, the task is to find the radius of the circle having area equal to the sum of the area of the two circles having given radii. Examples: Input:r1 = 8r2 = 6Output:10Explanation:Area of circle with radius 8 = 201.061929 Area of a circle with radius 6 = 113.097335Area of a circle with
5 min read
Number of rectangles in a circle of radius R
Given a circular sheet of radius R and the task is to find the total number of rectangles with integral length and width that can be cut from the circular sheet, one at a time. Examples: Input: R = 2 Output: 8 8 rectangles can be cut from a circular sheet of radius 2. These are: 1x1, 1x2, 2x1, 2x2, 1x3, 3x1, 2x3, 3x2.Input: R = 1 Output: 1 Only one
9 min read
Angular Sweep (Maximum points that can be enclosed in a circle of given radius)
Given ‘n’ points on the 2-D plane, find the maximum number of points that can be enclosed by a fixed-radius circle of radius ‘R’. Note: The point is considered to be inside the circle even when it lies on the circumference. Examples:  Input: R = 1 points[] = {(6.47634, 7.69628), (5.16828 4.79915), (6.69533 6.20378)}Output: 2The maximum number of po
15 min read
Count of Valid Partitions such that all Partitions lie in Range [1, L]
Given a string S containing only digits and an integer L, find the number of ways to partition the given string such that each partition forms a number that lies between the range [1, L]. Since the answer may be very large, return the answer modulo 109+7. Examples: Input: S = "1000", L = 10000Output: 1Explanation: The only possible partition is [10
8 min read
Make N pairs from Array as (X, Y) coordinate point that are enclosed inside a minimum area rectangle
Given a number N, and an array A[] of size 2N, the task is to make N pairs of these array elements and place them on an X-Y coordinate plane, such that they are enclosed inside a minimum area rectangle( with sides parallel to the X-axis and Y-axis) and print the area of the rectangle. Examples: Input: N = 4, A = {1, 4, 2, 5, 3, 6, 7, 8}Output: 9Exp
7 min read
Total cuts such that sum of largest of left and smallest of right is atleast K
Given an array A[] of size N and an integer K, the task is to find the total number of cuts that you can make such that for each cut these two conditions are satisfied: A cut divides an array into two parts of equal or unequal length (non-zero).Sum of the largest element in the left part and the smallest element in the right part is greater than or
6 min read
Remove nodes from Binary Tree such that sum of all remaining root-to-leaf paths is atleast K
Given a Binary Tree and an integer K, the task is to delete nodes from the given Tree such that the sum of all nodes of all remaining root to leaf paths is at least K. Examples: Input: K = 27 Output: 5 4 8 5 6 11Explanation:Below are the paths whose sum is less than 27: 5 -&gt; 3 -&gt; 9: Path Sum = 5 + 3 + 9 = 17.5 -&gt; 4 -&gt; 9: Path Sum = 5 +
11 min read
Number of ways of cutting a Matrix such that atleast one cell is filled in each part
Given an integer K and a matrix mat[][] containing 1 and 0, where 1 denotes the cell is filled and 0 denotes an empty cell. The task is to find the number of ways to cut the matrix into K parts using K-1 cuts such that each part of the matrix contains atleast one filled cell. For each cut, there must be a direction either horizontal or vertical. Th
12 min read
Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
Given a string str of lowercase English alphabets and an integer m. The task is to count how many positions are there in the string such that if you partition the string into two non-empty sub-strings, there are at least m characters with the same frequency in both sub-strings. The characters need to be present in the string str.Examples: Input: st
15+ min read
Find a point that lies inside exactly K given squares
Given an integer K and an array arr each of whose element x represents a square with two of its vertices as (0, 0) and (x, x). The task is to find a point which lies in exactly K squares. Examples: Input: arr[] = {1, 2, 3, 4}, K = 2 Output: (3, 3) The point (3, 3) lies inside 3rd and 4th square only. Input: arr[] = {8, 1, 55, 90}, K = 3 Output: (8,
3 min read
Find intersection point of lines inside a section
Given N lines in two-dimensional space in y = mx + b form and a vertical section. We need to find out whether there is an intersection point inside the given section or not. Examples: In below diagram four lines are there, L1 : y = x + 2 L2 : y = -x + 7 L3 : y = -3 L4 : y = 2x – 7 and vertical section is given from x = 2 to x = 4 We can see that in
9 min read
Find if a point lies inside, outside or on the circumcircle of three points A, B, C
Given four non-collinear points A, B, C, and P. The task is to find whether point P lies inside, outside or on the circumcircle formed by points A, B, and C.Examples Input: A = {2, 8}, B = {2, 1}, C = {4, 5}, P = {2, 4}; Output: Point (2, 4) is inside the circumcircle. Input: A = {2, 8}, B = {2, 1}, C = {4, 5}, P = {3, 0}; Output: Point (3, 0) lies
15+ min read
Minimum window size containing atleast P primes in every window of given range
Given three integers X, Y and P, the task is to find the minimum window size K such that every window in the range [X, Y] of this size have atleast P prime numbers.Examples: Input: X = 2, Y = 8, P = 2 Output: 4 Explanation: In the range [2, 8], window size of 4 contains atleast 2 primes in each window. Possible Windows - {2, 3, 4, 5} - No of Primes
15+ min read
Article Tags :
Practice Tags :