Create Maximum Number
In the Create Maximum Number problem, we have given two arrays of length n and m with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from the digits of the two. The relative order of the digits from the same array must …
Degree of an array
Problem Statement In the Degree of an array problem we have given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements. Your task is to find the smallest possible length of a (contiguous) subarray of nums, …
Java initialize Array
Arrays in java are the most widely used data structure that stores multiple values of the same data type in sequential order. The array has a fixed length and the index starts from 0 to n-1 where n is the length of an array. We can use arrays class in …
Search Insert Position
In the Search Insert Position problem, we have given an integer x and a sorted array a[ ] of size n. Find the appropriate index or position at which the given integer must be inserted if given integer, not in the array. If given integer present in the input array …
Find Peak Element
Let’s understand Find Peak Element problem. Today we have with us an array that needs its peak element. Now, you must be wondering as to what do I mean by the peak element? The peak element is one which is greater than all its neighbours. Example: Given an array of …
K-th Smallest Element in a Sorted Matrix
In K-th Smallest Element in a Sorted Matrix problem, we have given an n x n matrix, where every row and column is sorted in non-decreasing order. Find the kth smallest element in the given 2D array. Example Input 1: k = 3 and matrix = 11, 21, 31, 41 …
Pascal Triangle Leetcode
The Pascal Triangle is a very good Leetcode problem that is asked so many times in Amazon, Microsoft, and other companies. we have given non-negative integer rows, print first rows rows of the pascal triangle. Example rows = 5 rows = 6 Types of solution for Pascal Triangle Leetcode Dynamic Programming …
Valid Triangle Number
Problem In the Valid Triangle Number problem, we have given an array of non-negative integers. Find the number of triplets that can form a triangle. If we consider the numbers in the array as side lengths of the triangle. Example Input [ 2, 2, 3, 4 ] Output 3 Explanation We …
Maximum size subarray sum equals k
In Maximum size subarray sum equals k we have given an array of integers and a value k. You have to find the length of the longest subarray whose sum is equal to k. If no such subarray exists then return 0. One approach is to use hashtable and check …