Find Peak Element LeetCode Solution

Problem Statement Find Peak Element LeetCode Solution says that – A peak element is an element that is strictly greater than its neighbors. Given a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You may imagine …

Read more

Binary Search LeetCode Solution

Problem Statement Binary Search LeetCode Solution says that – Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [-1,0,3,5,9,12], target …

Read more

Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution

Problem Statement Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution – Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution says that – You are given a list of songs where the ith song has a duration of time[i] seconds. Return the number of pairs of songs for which …

Read more

Decode String Leetcode Solution

Problem Statement The Decode String LeetCode Solution – “Decode String” asks you to convert the encoded string into a decoded string. The encoding rule is k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times where k is a positive integer. Example: Input: s = “3[a]2[bc]” Output: “aaabcbc” …

Read more

Next Permutation Leetcode Solution

Problem Statement The Next Permutation LeetCode Solution – “Next Permutation” states that given an array of integers which is a permutation of first n natural numbers. We need to find the next lexicographically smallest permutation of the given array. The replacement must be in-place and use only constant extra space. …

Read more

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 …

Read more

3Sum Closest LeetCode Solution

Problem Statement 3Sum Closest LeetCode Solution – Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Input: nums = [-1,2,1,-4], target = 1 Output: …

Read more

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

Read more

Snakes and Ladders LeetCode Solution

Problem Statement Snakes and Ladders LeetCode Solution – You are given an n x n integer matrix board where the cells are labeled from 1 to n2 in a Boustrophedon style starting from the bottom left of the board (i.e. board[n – 1][0]) and alternating directions in each row. You start on the square 1 of the board. In each move, …

Read more

Coin Change 2 Leetcode Solution

Problem Statement The Coin Change 2 LeetCode Solution – “Coin Change 2” states that given an array of distinct integers coins and an integer amount, representing a total amount of money. We need to return the count of the total number of different possible combinations that sum to the amount.  …

Read more

Translate »