We represent color red, white, and blue with integers 0, 1, and 2 to represent respectively. Example: Input: Output: We can solve this by many different ways. Solution 1 will be counting all the number of 0’s, 1’s and 2’s. Then insert those number of elements …
Example 1: Input: matrix = , , ] target = 3 Output: true This problem can be solved in 2 ways. By eliminating one row or column at a time. By binary search. 1. By eliminating one row or column at a time. We start …
Example 1: Input: , , ] Output: , , ] We shall solve this problem by using 2 solutions. Be sure to understand both the solutions, as solution 2 is depended on solution 1. In solution 1 we shall make use of …
Example, path = "/home/", => "/home" path = "/x/./y/../../z/", => "/z" Corner Cases: Did you consider the case where path = “/../”? In this case, you should return “/”. Another corner case is the path might contain multiple slashes ‘/’ together, such as “/home//foo/”. In this case, you should ignore redundant slashes and return “/home/foo”. To solve this problem, …
You are given a m x n matrix with elements which represents cost. your goal is to start from top left and reach to bottom right with minimum cost. You can move only down or right. Example: Input: , , ] Output: 7 Minimum cost path …
Problem Explanation: A bike is located at the top-left corner of a m x n matrix. Bike can only move either down or right at any point in time. Bike is trying to reach the bottom-right corner of the matrix. There are some obstacles along the way, find the …
Example 1: Input: 1->2->3->4->5->NULL, k = 2 Output: 4->5->1->2->3->NULL Explanation: rotate 1 steps to the right: 5->1->2->3->4->NULL rotate 2 steps to the right: 4->5->1->2->3->NULL Algorithm: Step 1: Take 2 pointers pointing to the head pointer. new_head = tail = head Step 2: Get the length of the …