You are given a collection of intervals, merge all overlapping intervals. Example 1: Input: ,,,] Output: ,,] Explanation: Since intervals and overlaps, merge them into . This problem can be solved in 2 ways: Brute force approach By sorting the input array 1. Brute Force approach …
Given an array of positive integers, you are at index 0, each element will represents maximum jump length. Check if you can reach to last index. Example 1: Input: Output: true Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last …
Example 1: Input: , , ] Output: The Solution is very simple. As shown in the image above, We traverse right We traverse down We traverse left We traverse up To achieve this, we take 4 variables: rowStart = 0; rowEnd = matrix.size()-1; colStart = 0; …
Example 1: Input: 2.00000, 10 Output: 1024.00000 Achieve it within O(log n) This problem can be solved in 4 different ways: Recursive Iterative Divide and Conquer Bit Manipulation We shall look at the first 3 methods. So let us understand how pow(x ^ n) means. It …
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. Input: Output: 6 Before solving this problem, please take a look at “Container with most water” problem. There I have explained …
Example: Input: , Output: , , ] This problem can be solved easily using Maps. The solution involves 2 steps: Sort the element and make it as the key. Take the value and place it in the key. In our example: Pass 1: …
Note: You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. Example 1: Given input matrix = , , ], rotate the input matrix in-place such that it becomes: …
In this chapter we shall learn about: Structure Introduction Declaration and initialization of structure Size of a structure. Bit fields Structure padding Structure with in a structure Array of Structure Pointer to structure Structure and functions Typedef Unions Enums 1. Structure Introduction: Structure is …