Convert Sorted Array to height-balanced Binary Search Tree

Problem Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. Examples Example 1: Input: nums = [1, 2, 3, 4, 5, 6] Output: [3,2,5,1,null,4,6] Explanation: [4,2,5,1,3,null,6] is also accepted. ...

Unique Paths in Grid 1-2 - Get all paths moving right or down

Problem There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time. Given the two integers m and n, return all possible unique paths that the robot can take to reach the bottom-right corner. ...

Find Second largest element in an array

Problem Given an array of integers, our task is to write a program that efficiently finds the second largest element present in the array. Similar problem - Find smallest and second smallest elements in an array Examples Example 1: Input : arr[] = {12, 35, 1, 10, 34, 1} Output : 34 Example 2: Input : arr[] = {10, 5, 10} Output : 5 ...

Subsets 1 Problem

Problem Given a set of distinct integers/characters, S, return all possible subsets. OR Given an integer array nums of unique elements, return all possible subsets (the power set). Examples If we’re given a set of integers such that S = {1, 2, 3}, how can we find all the subsets of that set? For example, given S, the set of all subsets i.e. P(S) we get are {}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, and {1, 2, 3}. Here is {} is empty set denoted by Φ. ...

Check if Array is Consecutive Integers

Problem Given a array of unsorted numbers, check if all the numbers in the array are consecutive numbers. Examples Example 1: Input: int [] nums = {21,24,22,26,23,25}; Output: True Explanation: All the integers are consecutive from 21 to 26 Example 2: Input: int [] nums = {11,10,12,14,13}; Output: True Explanation: All the integers are consecutive from 10 to 14 ...

Check if Array is Consecutive Positive Integers

Problem Given a array of unsorted numbers, check if all the numbers in the array are consecutive numbers. This problem is special case for Check if Array is Consecutive Integers. Examples Example 1: Input: int [] nums = {21,24,22,26,23,25}; Output: True Explanation: All the integers are consecutive from 21 to 26 Example 2: ...

Find most frequent element in the array

Problem Given an array of integers, write a algorithm to find the element which appears maximum number of times in the array. Examples Example 1: int [] arrA = {4, 1, 5, 2, 1, 5, 9, 8, 6, 5, 3, 2, 4, 7}; Output: Element repeating maximum no of times: 5, maximum count: 3 Similar Problem Find the element which appears maximum number of times in the ranged array0, n) ...

Finding the Maximum Distance Between Increasing Elements in an Array

Problem Given an array arr[], find the maximum j – i such that arr[j] > arr[i]. Examples Example 1: Input: {34, 8, 10, 3, 2, 80, 30, 33, 1} Output: 6 (j = 7, i = 1) Example 2: Input: {9, 2, 3, 4, 5, 6, 7, 8, 18, 0} Output: 8 ( j = 8, i = 0) ...

Longest Common Prefix in array of string

Problem Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". OR Given a sentence, give Longest Sequence Of Prefix Shared By All The Words In A String Longest common prefix for a pair of strings S1 and S2 is the longest string S which is the prefix of both S1 and S2. ...

Find duplicate number in array with 1 to N+1 numbers with one number repeating

Problem Suppose you have an array of 1001 integers. The integers are in random order, but you know each of the integers is between 1 and 1000 (inclusive). In addition, each number appears only once in the array, except for one number, which occurs twice. Assume that you can access each element of the array only once. Describe an algorithm to find the repeated number. If you used auxiliary storage in your algorithm, can you find an algorithm that does not require it? ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy