Leetcode Detailed Solutions

Leetcode 1614: Maximum Nesting Depth of the Parentheses

Category: Easy Problem A string is a valid parentheses string (denoted VPS) if it meets one of the following: It is an empty string “”, or a single character not equal to “(” or “)”, It can be written as AB (A concatenated with B), where A and B are VPS‘s, or It can be written as (A), where A is a VPS. We can similarly define the nesting depth depth(S) of any VPS S as follows: depth(“”) = 0

Leetcode 1614: Maximum Nesting Depth of the Parentheses Read More »

Leetcode 1295: Find Numbers with Even Number of Digits

Category : Easy Problem Given an array nums of integers, return how many of them contain an even number of digits. https://leetcode.com/problems/find-numbers-with-even-number-of-digits/ Examples Example 1: Example 2: Constraints 1 <= nums.length <= 500 1 <= nums[i] <= 10^5 Solution Approach The problem states that we need to find a count of all the numbers in the array which has

Leetcode 1295: Find Numbers with Even Number of Digits Read More »

Leetcode 1486: XOR Operation in an Array

Category : Easy Problem Given an integer n and an integer start. Define an array nums where nums[i] = start + 2*i (0-indexed) and n == nums.length. Return the bitwise XOR of all elements of nums. https://leetcode.com/problems/xor-operation-in-an-array/ Examples Example 1: Example 2: Example 3: Example 4: Constraints 1 <= n <= 1000 0 <= start <= 1000 n == nums.length Solution Approach In this problem, we

Leetcode 1486: XOR Operation in an Array Read More »

Subtract the Product and Sum of Digits of an Integer

Leetcode 1281: Subtract the Product and Sum of Digits of an Integer

Category : Easy Problem Given an integer number n, return the difference between the product of its digits and the sum of its digits. https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/ Examples Example 1: Example 2: Constraints 1 <= n <= 10^5 Solution Approach In this question, you just need to find the sum and product of the digits of a given

Leetcode 1281: Subtract the Product and Sum of Digits of an Integer Read More »

Leetcode 1528: Shuffle String

Category : Easy Problem Given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string. Return the shuffled string. https://leetcode.com/problems/shuffle-string/ Examples Example 1: Example 2: Example 3: Example 4: Example 5: Constraints s.length == indices.length == n 1 <= n <= 100 s contains only

Leetcode 1528: Shuffle String Read More »

Leetcode 1431: Kids With the Greatest Number of Candies

Category : Easy Problem Given the array candies and the integer  extraCandies, where  candies[i] represents the number of candies that the ith kid has. For each kid check if there is a way to distribute  extraCandies among the kids such that he or she can have the greatest number of candies among them. Notice that multiple kids can have the greatest number of candies. https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/ Examples Example 1:

Leetcode 1431: Kids With the Greatest Number of Candies Read More »

Leetcode 1365: How Many Numbers Are Smaller Than the Current Number

Category : Easy Problem Given the array nums for each  nums[i] find out how many numbers in the array are smaller than it. That is, for each  nums[i] you have to count the number of valid  j's such that  j != i and  nums[j] < nums[i]. Return the answer in an array. https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/ Examples Example 1: Example 2: Example 3: Constraints: 2 <= nums.length <= 500 0

Leetcode 1365: How Many Numbers Are Smaller Than the Current Number Read More »

Leetcode 1480: Running Sum of 1d Array

Category : Easy Problem Given an array  nums. We define a running sum of an array as  runningSum[i] = sum(nums[0]nums[i]). Return the running sum of  nums. https://leetcode.com/problems/running-sum-of-1d-array Examples Example 1: Example 2: Example 3: Constraints 1 <= nums.length <= 1000 -10^6 <= nums[i] <= 10^6 Solution Approach In this question, you just need to find the running sum i.e the at any

Leetcode 1480: Running Sum of 1d Array Read More »