leetCode

Explore 34 articles about leetcode with interactive visualizations and step-by-step explanations.

34 Articles
Interactive Visualizations
Step-by-Step Guides
leetCodeleetCode_arrays
1 min read

1920. Build Array from Permutation | LeetCode Solution | JavaScript | 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.

P

Pranay Kothapalli

Oct 21, 2024

Read More
leetCodeleetCode_arrays
1 min read

1929. Concatenation of Array | LeetCode Solution | JavaScript | 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).

P

Pranay Kothapalli

Oct 21, 2024

Read More
leetCodeleetCode_arrays
1 min read

2011. Final Value of Variable After Performing Operations | LeetCode Solution | JavaScript | Easy

There is a programming language with only four operations and one variable X: ++X and X++ increments the value of the variable X by 1. --X and X-- decrements the value of the variable X by 1.

P

Pranay Kothapalli

Oct 21, 2024

Read More
leetCodeleetCode_arrays
1 min read

3190. Find Minimum Operations to Make All Elements Divisible by Three | LeetCode Solution | JavaScript | Easy

You are given an integer array nums. In one operation, you can add or subtract 1 from any element of nums. Return the minimum number of operations to make all elements of nums divisible by 3.

P

Pranay Kothapalli

Oct 21, 2024

Read More
leetCodeleetCode_arrays
2 min read

3146. Permutation Difference between Two Strings | LeetCode Solution | JavaScript | Easy

You are given two strings s and t such that every character occurs at most once in s and t is a permutation of s. The permutation difference between s and t is defined as the sum of the absolute difference between the index of the occurrence of each character.

P

Pranay Kothapalli

Aug 02, 2024

Read More
leetCodeleetCode_arrays
2 min read

3162. Find the Number of Good Pairs I | LeetCode Solution | JavaScript | Easy

You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k. A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k.

P

Pranay Kothapalli

Aug 01, 2024

Read More
leetCodeleetCode_arrays
2 min read

3168. Minimum Number of Chairs in a Waiting Room | LeetCode Solution | JavaScript | Easy

You are given a string s. Simulate events at each second i: If s[i] == 'E', a person enters the waiting room and takes one of the chairs in it. If s[i] == 'L', a person leaves the waiting room, freeing up a chair.

P

Pranay Kothapalli

Aug 01, 2024

Read More
leetCodeleetCode_arrays
2 min read

2810. Faulty Keyboard | LeetCode Solution | JavaScript | Easy

Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected.

P

Pranay Kothapalli

Jul 29, 2024

Read More
leetCodeleetCode_arrays
2 min read

3200. Maximum Height of a Triangle | LeetCode Solution | JavaScript | Easy

You are given two integers red and blue representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1st row will have 1 ball, the 2nd row will have 2 balls, and so on.

P

Pranay Kothapalli

Jul 29, 2024

Read More
leetCodeleetCode_arrays
1 min read

3232. Find if Digit Game Can Be Won | LeetCode Solution | JavaScript | Easy

You are given an array of positive integers nums. Alice and Bob are playing a game. In the game, Alice can choose either all single-digit numbers or all double-digit numbers from nums.

P

Pranay Kothapalli

Jul 29, 2024

Read More
leetCodeleetCode_arrays
1 min read

58. Length of Last Word | LeetCode Solution | JavaScript | Easy

Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only.

P

Pranay Kothapalli

Jul 28, 2024

Read More
leetCodeleetCode_arrays
2 min read

414. Third Maximum Number | LeetCode Solution | JavaScript | Easy

Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number.

P

Pranay Kothapalli

Jul 26, 2024

Read More
leetCodeleetCode_arrays
1 min read

448. Find All Numbers Disappeared in an Array | LeetCode Solution | JavaScript | Easy

Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.

P

Pranay Kothapalli

Jul 26, 2024

Read More
leetCodeleetCode_arrays
2 min read

66. Plus One | LeetCode Solution | JavaScript | Easy

You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order.

P

Pranay Kothapalli

Jul 26, 2024

Read More
leetCodeleetCode_arrays
1 min read

1051. Height Checker | LeetCode Solution | JavaScript | Easy

A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height.

P

Pranay Kothapalli

Jul 23, 2024

Read More
leetCodeleetCode_arrays
2 min read

283. Move Zeroes | LeetCode Solution | JavaScript | Easy

Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. You must do this in-place without making a copy of the array.

P

Pranay Kothapalli

Jul 23, 2024

Read More
leetCodeleetCode_arrays
1 min read

905. Sort Array By Parity | LeetCode Solution | JavaScript | Easy

Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers. Return any array that satisfies this condition.

P

Pranay Kothapalli

Jul 23, 2024

Read More
leetCodeleetCode_arrays
1 min read

1299. Replace Elements with Greatest Element on Right Side | LeetCode Solution | JavaScript | Easy

Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array.

P

Pranay Kothapalli

Jul 16, 2024

Read More
LeetCodeleetcode
1 min read

1346. Check If N and Its Double Exist | LeetCode Solution | JavaScript | Easy

Given an array arr of integers, check if there exist two indices i and j such that i != j, 0 <= i, j < arr.length, and arr[i] == 2 * arr[j].

P

Pranay Kothapalli

Jul 15, 2024

Read More
LeetCodeleetcode
2 min read

941. Valid Mountain Array | LeetCode Solution | JavaScript | Easy

Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if it has a peak.

P

Pranay Kothapalli

Jul 15, 2024

Read More
LeetCodeleetcode
1 min read

26. Remove Duplicates from Sorted Array | LeetCode Solution | JavaScript | Easy

Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same.

P

Pranay Kothapalli

Jul 14, 2024

Read More
LeetCodeleetcode
2 min read

27. Remove Element | LeetCode Solution | JavaScript | Easy

Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.

P

Pranay Kothapalli

Jul 14, 2024

Read More
LeetCodeleetcode
2 min read

88. Merge Sorted Array | LeetCode Solution | JavaScript | Easy

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.

P

Pranay Kothapalli

Jul 13, 2024

Read More
LeetCodeleetcode
1 min read

1089. Duplicate Zeros | LeetCode Solution | JavaScript | Easy

Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.

P

Pranay Kothapalli

Jul 12, 2024

Read More
LeetCodeleetcode
1 min read

1295. Find Numbers with Even Number of Digits | LeetCode Solution | JavaScript | Easy

Another problem - Find Numbers with Even Number of Digits from LeetCode's 101 Array course. This was a pretty easy one to solve, You simply loop through all the numbers.

P

Pranay Kothapalli

Jul 12, 2024

Read More
LeetCodeleetcode
2 min read

383. Ransom Note | LeetCode Solution | JavaScript | Easy

I will be solving the Ransom Note problem from LeetCode today, this requires you to utilize a hashmap to solve this. I took a while to solve this perfectly, I spent almost 20 minutes trying to create 2 hashes.

P

Pranay Kothapalli

Jul 12, 2024

Read More
LeetCodeleetcode
1 min read

485. Max Consecutive Ones | LeetCode Solution | JavaScript | Easy

Introduced in the Arrays 101 track of LeetCode. I first solved this and got it wrong by over-complicating it. Deleted the whole code and tried a simpler approach.

P

Pranay Kothapalli

Jul 12, 2024

Read More
LeetCodeleetcode
2 min read

977. Squares of a Sorted Array | LeetCode Solution | JavaScript | Easy

Solving Squares of a Sorted Array was pretty easy, I encountered this in the Arrays 101 course of LeetCode's Explore cards. It was straightforward, first I looped through an array by multiplying every number with itself.

P

Pranay Kothapalli

Jul 12, 2024

Read More
LeetCodeleetcode
1 min read

1342. Number of Steps to Reduce a Number to Zero | LeetCode Solution | JavaScript | Easy

An attempt at solving LeetCode's Number of Steps to Reduce a Number to Zero. It shouldn't take you more than a few minutes for you to get it right. Pretty easy.

P

Pranay Kothapalli

Jul 11, 2024

Read More
LeetCodeleetcode
1 min read

1672. Richest Customer Wealth | LeetCode Solution | JavaScript | Easy

Today, I solved the Richest Customer Wealth on LeetCode. A pretty straightforward approach for solving this, we're given a 2-dimensional array, we need to loop over them, and maintain one variable for max_wealth.

P

Pranay Kothapalli

Jul 11, 2024

Read More
LeetCodeleetcode
1 min read

412. Fizz Buzz | LeetCode Solution | JavaScript | Easy

Coming back to solving FizzBuzz after almost a decade brings back a lot of memories. I remember the FizzBuzz program was known to be very easy. It also teaches us the importance of ordering logical statements.

P

Pranay Kothapalli

Jul 11, 2024

Read More
LeetCodeleetcode
2 min read

876. Middle of the Linked List | LeetCode Solution | JavaScript | Easy

A supposedly stepped-up difficult problem in easy mode on the Explore Course I was doing. It isn't tough if you know how to traverse a Linked List.

P

Pranay Kothapalli

Jul 11, 2024

Read More
LeetCodeleetcode
1 min read

1. Two Sum | LeetCode Solution | JavaScript | Easy

I had just added support for category tags on my blog, LeetCode makes a debut! It's customary to begin my LeetCode journey by solving the first problem. Two Sum Problem.

P

Pranay Kothapalli

Jul 10, 2024

Read More
LeetCodeleetcode
1 min read

1480. Running Sum of 1d Array | LeetCode Solution | JavaScript | Easy

A pretty straightforward approach for solving this, we add the adjacent numbers in an array and return the final resultant array.

P

Pranay Kothapalli

Jul 10, 2024

Read More