Skip to content

TheCoderSingh/Leetcode-Javascript-Solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Solved Problems

My LeetCode Solutions

#TitleDescriptionSolution
1Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.Solution
7Reverse IntegerGiven a 32-bit signed integer, reverse digits of an integer.Solution
8String to Integer (atoi)Implement atoi which converts a string to an integer.Solution
9Palindrome NumberGiven an integer, return true if it is a palindrome, and false otherwise.Solution
12Integer to RomanGiven an integer, convert it to a roman numeral.Solution
13Roman to IntegerGiven a roman numeral, convert it to an integer.Solution
14Longest Common PrefixFind the longest common prefix string amongst an array of strings.Solution
20Valid ParenthesesGiven a string, determine if the input string is valid.Solution
65Valid NumberValidate if a given string can be interpreted as a decimal number.Solution
66Plus OneIncrement the large integer by one and return the resulting array of digits.Solution
94Binary Tree Inorder TraversalGiven the root of a binary tree, return the inorder traversal of its nodes' values.Solution
100Same TreeGiven the roots of two binary trees p and q, write a function to check if they are the same or not.Solution
104Maximum Depth of Binary TreeGiven the root of a binary tree, return its maximum depth.Solution
125Valid PalindromeGiven a string s, return true if it is a palindrome, or false otherwise.Solution
136Single NumberGiven a non-empty array of integers nums, every element appears twice except for one. Find that single one.Solution
141Linked List CycleReturn true if there is a cycle in the linked list. Otherwise, return false.Solution
167Two Sum IIGiven a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Return the indices of the two numbers, added by one as an integer array of length 2.Solution
169Majority ElementGiven an array nums of size n, return the majority element.Solution
175Combine Two TablesReport the first name, last name, city, and state of each person in the table.Solution
204Count PrimesCount the number of prime numbers less than a non-negative number, n.Solution
242Valid AnagramGiven two strings s and t, return true if t is an anagram of s, and false otherwise.Solution
258Add DigitsGiven an integer, repeatedly add all its digits until the result has only one digit.Solution
283Move ZeroesGiven an integer array, move all 0's to the end of it while maintaining the relative order of the non-zero elements.Solution
344Reverse StringWrite a function that reverses a string. The input string is given as an array of characters s.Solution
349Intersection of Two ArraysGiven two integer arrays, return an array of their intersection.Solution
389Find the DifferenceYou are given two strings s and t. String t is generated by random shuffling string s and then add one more letter at a random position. Return the letter that was added to t.Solution
448Find All Numbers Disappeared in an ArrayGiven an array of integers, return an array of all the integers that do not appear in nums.Solution
584Find Customer RefereeFind the names of the customer that are not referred by the customer with id = 2.Solution
595Big CountriesA country is big if it has an area of bigger than 3 million square km or a population of more than 25 million. Write a SQL solution to output big countries' name, population and area.Solution
620Not Boring MoviesWrite a SQL query to output movies with an odd numbered ID and a description that is not 'boring'.Solution
665Non-decreasing ArrayGiven an array, check if it could become non-decreasing by modifying at most 1 element.Solution
704Binary SearchGiven an array of integers, write a function to search target in nums.Solution
709To Lower CaseImplement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.Solution
771Jewels and StonesYou're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.Solution
922Sort Array By Parity IIGiven an array of integers nums, half of the integers in nums are odd, and the other half are even. Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even. Return any answer array that satisfies this condition.Solution
933Number of Recent CallsReturn the number of requests that have happened in the inclusive rangeSolution
1108Defanging an IP AddressGiven a valid IP address, return a defanged version of that IP address.Solution
1148Article Views IWrite a solution to find all the authors that viewed at least one of their own articles. Return the result table sorted by id in ascending order.Solution
1207Unique Number of OccurrencesGiven an array of integers, write a function that returns true if and only if the number of occurrences of each value in the array is unique.Solution
1281Subtract the Product and Sum of Digits of an IntegerGiven an integer, return the difference between the product of its digits and the sum of its digits.Solution
1295Numbers with Even Number of DigitsGiven an array nums of integers, return how many of them contain an even number of digits.Solution
1313Decompress Run-Length Encoded ListWe are given a list nums of integers representing a list compressed with run-length encoding. Consider each adjacent pair of elements [freq, val] = [nums[2i], nums[2i+1]] (with i >= 0). For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.Solution
1342Number of Steps to Reduce a Number to ZeroGiven a non-negative integer num, return the number of steps to reduce it to zero. If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.Solution
1365How Many Numbers Are Smaller Than the Current NumberGiven 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].Solution
1046Last Stone WeightReturn the weight of the last remaining stone. If there are no stones left, return 0.Solution
1431Kids With the Greatest Number of CandiesFor 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.Solution
1470Shuffle the ArrayGiven 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].Solution
1476Subrectangle QueriesImplement the class SubrectangleQueries which receives a rows x cols rectangle as a matrix of integers in the constructor and supports two methods.Solution
1480Running Sum of 1d ArrayGiven 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.Solution
1486XOR Operation in an ArrayGiven 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.Solution
1512Number of Good PairsGiven an array of integers nums. A pair (i,j) is called good if nums[i] == nums[j] and i < j. Return the number of good pairs.Solution
1528Shuffle StringGiven 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.Solution
1603Design Parking SystemDesign a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size.Solution
1672Richest Customer WealthYou are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth 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.Solution
1683Invalid TweetsWrite a solution to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15.Solution
1757Recyclable and Low Fat ProductsWrite a solution to find the ids of products that are both low fat and recyclable.Solution
1920Build Array from PermutationGiven 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.Solution
1929Concatenation of ArrayGiven 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.Solution
2011Final Value of Variable After Performing OperationsGiven an array of strings operations containing a list of operations, return the final value of X after performing all the operations.Solution
2114Maximum Number of Words Found in SentencesReturn the maximum number of words that appear in a single sentence.Solution
2235Add Two IntegersGiven two integers num1 and num2, return the sum of the two integers.Solution
2413Smallest Even MultipleGiven a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.Solution
2469Convert the TemperatureYou should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit].Solution
2703Return Length of Arguments PassedWrite a function argumentsLength that returns the count of arguments passed to it.Solution
2723Add Two PromisesGiven two promises, return a new promise. The returned promise should resolve with the sum of the two numbers.Solution
2769Find the Maximum Achievable NumberReturn the maximum possible achievable number.Solution
2942Find Words Containing CharacterYou are given an array of strings words and a character. Return an array of indices representing the words that contain the character.Solution
2951Find the PeaksReturn an array that consists of indices of peaks in the given array in any order.Solution
close