Category Archives: Geometric

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 »

Paper Cut into Minimum Number of Squares

Given a paper of size A x B. Task is to cut the paper into squares of any size. Find the minimum number of squares that can be cut from the paper. Examples: Input : 13 x 29 Output : 9 Explanation : 2 (squares of size 13×13) + 4 (squares of size 3×3) +… Read More »

Count of parallelograms in a plane

Given some points on a plane, which are distinct and no three of them lie on the same line. We need to find number of Parallelograms with the vertices as the given points. Examples: Input : points[] = {(0, 0), (0, 2), (2, 2), (4, 2), (1, 4), (3, 4)} Output : 2 Two Parallelograms… Read More »