Category Archives: Geometric

Minimum block jumps to reach destination

Given N lines and one starting point and destination point in 2-dimensional space. These N lines divide the space into some blocks. We need to print the minimum number of jumps to reach destination point from starting point. We can jump from one block to other block only if they share a side. Examples: Input… Read More »

Minimum lines to cover all points

Given N points in 2-dimensional space, we need to print the count of the minimum number of lines which traverse through all these N points and which go through a specific (xO, yO) point also. Examples: If given points are (-1, 3), (4, 3), (2, 1), (-1, -2), (3, -3) and (xO, yO) point is… Read More »

Pizza cut problem (Or Circle Division by Lines)

Given number of cuts, find the maximum number of possible pieces. Examples: Input : 2 Output : 4 Input : 3 Output : 7 This problem is nothing but The Lazy Caterer’s Problem and has below formula. Maximum number of pieces = 1 + n*(n+1)/2 Refer this for proof. Output: 7 This article is contributed… Read More »

Check if four segments form a rectangle

We are given four segments as a pair of coordinates of their end points. We need to tell whether those four line segments make a rectangle or not. Examples: Input : segments[] = [(4, 2), (7, 5), (2, 4), (4, 2), (2, 4), (5, 7), (5, 7), (7, 5)] Output : Yes Given these segment… Read More »

Minimum distance to travel to cover all intervals

Given many intervals as ranges and our position. We need to find minimum distance to travel to reach such a point which covers all the intervals at once. Examples: Input : Intervals = [(0, 7), (2, 14), (4, 6)] Position = 3 Output : 1 We can reach position 4 by traveling distance 1, at… Read More »

Count of acute, obtuse and right triangles with given sides

Given an array of n positive distinct integers representing lengths of lines that can form triangle. The task is to find the number of acute triangles, obtuse triangles, and right triangles separately that can be formed from the given array. Examples: Input : arr[] = { 2, 3, 9, 10, 12, 15 }. Output :… Read More »