How Many Numbers Are Smaller Than the Current Number

1365. How Many Numbers Are Smaller Than the Current Number (Easy) 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. Example 1: Input: nums = [8,1,2,2,3] Output: … Read more

Number of Good Pairs (LeetCode)

1512. Number of Good Pairs (Easy) Given an array of integers nums, return the number of good pairs. A pair (i, j) is called good if nums[i] == nums[j] and i < j. Example 1: Input: nums = [1,2,3,1,1,3] Output: 4 Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed. Example 2: Input: nums = [1,1,1,1] Output: 6 Explanation: Each pair in the array are good. … Read more

Kids With the Greatest Number of Candies

1431. Kids With the Greatest Number of Candies (Easy) There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you have. Return a boolean array result of length n, where result[i] is true if, after giving the ith kid all the extraCandies, they will have the greatest number of candies among … Read more

Richest Customer Wealth (LeetCode)

1672. Richest Customer Wealth (Easy) You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i​​​​​​​​​​​th​​​​ the customer has in the j​​​​​​​​​​​th​​​​ bank. Return the wealth that the richest customer has. A customer’s wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth. Example 1: Input: accounts = [[1,2,3],[3,2,1]] … Read more

Running Sum of 1d Array (LeetCode)

1480. Running Sum of 1d Array (Easy) 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. Example 1: Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4]. Example 2: Input: nums = [1,1,1,1,1] Output: [1,2,3,4,5] Explanation: Running sum … Read more

Concatenation of Array (LeetCode)

1929. Concatenation of Array (Easy) Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). Specifically, ans is the concatenation of two nums arrays. Return the array ans. Example 1: Input: nums = [1,2,1] Output: [1,2,1,1,2,1] Explanation: The array ans is formed as follows: – ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]] – ans = [1,2,1,1,2,1] … Read more

Build Array from Permutation (LeetCode)

1920. Build Array from Permutation (Easy) Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it. A zero-based permutation nums is an array of distinct integers from 0 to nums.length – 1 (inclusive). Example 1: Input: nums = [0,2,1,5,3,4] Output: [0,1,2,4,5,3] Explanation: The array ans is built as follows: ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]] = … Read more

Charlie has a magic mirror program in C

Charlie has a magic mirror program in C (Problem) Charlie has a magic mirror. The mirror shows right rotated versions of a given word. To generate different right-rotations of a word. Write the word in a circle in clockwise order, then start reading from any given character in clockwise order till you have covered all … Read more