Leetcode Detailed Solutions

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 »

Leetcode 9: Palindrome Number

Category : Easy Problem Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Follow up: Could you solve it without converting the integer to a string? https://leetcode.com/problems/palindrome-number/ Examples Example 1: Example 2: Example 3: Example 4: Constraints -231 <= x <= 231 – 1 Solution Approach To check if the number is …

Leetcode 9: Palindrome Number Read More »

Leetcode 1470: Shuffle the Array

Category : Easy Problem Given the array nums consisting of 2n elements in the form [x1,x2,…,xn,y1,y2,…,yn]. Return the array in the form [x1,y1,x2,y2,…,xn,yn]. https://leetcode.com/problems/shuffle-the-array/ Examples Example 1:

Example 2:

Example 3:

Constraints: 1 <= n <= 500 nums.length == 2n 1 <= nums[i] <= 10^3 Solution Approach The solution is pretty straight forward you just need to find …

Leetcode 1470: Shuffle the Array Read More »

Leetcode 20

Leetcode 20: Valid Parenthesis

Category : Easy Problem Given a string s containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. leetcode.com/problems/valid-parentheses/ Examples: Example 1

Example 2

Example 3

Example …

Leetcode 20: Valid Parenthesis Read More »