Problem Statement: You are given an array, you need to check if there are 3 consecutive odds exist. If exist then return true else false. Example Input: arr = Output: false Solution The solution is very simple. Just iterate throught the array and check if …
Problem Statement: You are given an unsorted array, you need to return the inversion count. Inversion count is the number of swaps required to make the array as sorted. If the input array is already sorted, then inversion count is 0. Example: Example 1: arr …
Problem Statement You are given 2 sorted arrays, merge and sort the two arrays in such a way that the initial numbers are in the first array other will be in the next array, Example: Input: arr1 = {20}; arr2 = {4, 5}; Now, the combined …
Problem Statement: You are given an array of integers having “n+1” integers. The integers in the array will be from . There will be one duplicate number and return the duplicate number. Example: Input: arr = {1, 2, 1} Output: 1 Solution: We can solve …
Question: Given an arrays, rotate it one time cyclically Example: Input : arr = {1, 2, 3, 4, 5, 6, 7, 8} Output: Rotating it one time will become {8, 1, 2, 3, 4, 5, 6, 7} We can modify the question, to rotate …
Question: Given 2 sorted arrays, find the union and intersection Example: Input : arr1 = {1, 3, 4, 6, 8} arr2 = {2, 3, 5, 7, 8} Output: Union : {1, 2, 3, 4, 5, 6, 7, 8} Intersection : {3, 8} Union of 2 arrays …
Question: Given an unsorted array with positive and negative elements, move all the elements to the beginning of the array. Example: Input : {5, -6, 7, -8, 9, -10} Output : {-8, -6, -10, 5, 9, 7} We can solve this by many different methods. …