![]() |
VOOZH | about |
Given a rectangle of length L, and width, W, the task is to generate all integral coordinates (X, Y) that lie within a rectangle pf dimensions L * W having one of its vertexes in the origin (0, 0).
Examples:
Input: L = 3, W = 2
Output: (0, 0) (0, 1) (1, 0) (1, 1) (2, 0) (2, 1)
Explanation: Total number of integral coordinates existing within the rectangle are L × W = 6. Therefore, the output is (0, 0) (0, 1) (1, 0) (1, 1) (2, 0) (2, 1).Input: L = 5, W = 3
Output: (0, 0) (0, 1) (0, 2) (1, 0) (1, 1) (1, 2) (2, 0) (2, 1) (2, 2) (3, 0) (3, 1) (3, 2) (4, 0) (4, 1) (4, 2)
Approach: The problem can be solved by generating all integral numbers from the range 0 to L for X-coordinates and from 0 to W for Y-coordinates using the rand() function. Follow the steps below to solve the problem:
Below is the implementation of the above approach:
(0, 0) (0, 1) (1, 0) (1, 1) (2, 0) (2, 1)
Time Complexity: O(L * W)
Auxiliary Space: O(L * W)