Add to Array-Form of Integer Problem

Problem The array-form of an integer num is an array representing its digits in left to right order. For example, for num = 1321, the array form is [1,3,2,1]. Given num, the array-form of an integer, and an integer k, return the array-form of the integer num + k. Examples Example 1: Input: num = [1,2,0,0], k = 34 Output: [1,2,3,4] Explanation: 1200 + 34 = 1234 ...

Kth Largest Element in an Array

Problem Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: nums = [3,2,1,5,6,4], k = 2 Output: 5 Example 2: Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 Output: 4 ...

Kth Smallest Element Using Randomized Selection

Problem Input - array A with n distinct numbers and a number i ∈ {1, 2, …, n} Output : ith order statistic i.e. ith smallest element of the input array Solution We have already seen multiple solutions here - Kth OR Nth Smallest Element in an Array. Here will focus on Linear time or O(n) solution. Finding the ith smallest element may seem difficult at first, but is it possible to find some O(n) or linear time solution. ...

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 ...

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: ...

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. ...

Array Sorting Problem

Problem Given an array of integers nums, sort the array in ascending order. You must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallest space complexity possible. Examples Input: Array of numbers , unsorted. Eg. ...

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