## Valid Triangle Number LeetCode Solution

Problem Statement Valid Triangle Number LeetCode Solution – Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle. Input: nums = [2,2,3,4] Output: 3 Explanation: Valid combinations are: 2,3,4 (using the first 2) …

## Valid Triangle Number LeetCode Solution

Problem Statement: Valid Triangle Number LeetCode Solution says – Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle. Example 1: Input: nums = [2,2,3,4] Output: 3 Explanation: Valid combinations are: 2,3,4 (using …

## Diagonal Traversal LeetCode Solution

Problem Statement Diagonal Traversal LeetCode Solution – Given a 2D integer array nums, return all elements of nums in diagonal order as shown in the below images. Input: nums = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,4,2,7,5,3,8,6,9] Explanation for Diagonal Traversal LeetCode Solution Key Idea The first row and the last column in this problem would serve …

## Brightest Position on Street LeetCode Solution

Problem Statement Brightest Position on Street LeetCode Solution – We are asked to assume a number line representing a street. This street contains lamp(s) on it. We are given a 2D integer array “lights”. Each lights[i] = [position_i, range_i] indicates that there is a street lamp on position_i which can …

## Asteroid Collision LeetCode Solution

Problem Statement Asteroid Collision LeetCode Solution – We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state …

## Diagonal Traverse LeetCode Solution

Problem Statement Diagonal Traverse LeetCode Solution – Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order. Input: mat = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,4,7,5,3,6,8,9] Explanation Consider the indices of the diagonals of an NxM matrix. Let’s use a 4×4 matrix as an example: …

## Number of Orders in the Backlog Leetcode Solution

Problem Statement The Number of Orders in the Backlog LeetCode Solution – “Number of Orders in the Backlog” states that given the 2D integer array [price, amount, orderType] which denotes that amount orders have been placed of type order type. If the order type is : 0, denotes the current …

## Check given array of size n can represent BST of n levels or not

Problem Statement Given an array with n elements, check given array of size n can represent BST of n levels or not. That is to check whether the binary search tree constructed using these n elements can represent a BST of n levels. Examples arr[] = {10, 8, 6, 9, …

## Pair of Positive Negative Values in an Array

In pair of positive negative values in an array problem we have given an array A of distinct integers, print all the pairs having positive value and negative value of a number that exists in the array. We need to print pairs in order of their occurrences. A pair whose …

## Reversing the First K elements of a Queue

In reversing the first K elements of a queue problem we have given a queue and a number k, reverse the first k elements of a queue using standard operations of the queue. Examples Input: queue = 10 -> 15 -> 31 -> 17 -> 12 -> 19 -> 2 …

Translate »