20. Valid Parentheses Leetcode solution in JavaSctipt (js)

0 Problem Given a string s containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid. An input string is valid if: Example 1: Input: s = “()” Output: true Example 2: Input: s = “()[]{}” Output: true Example 3: Input: s = “(]” Output: false Constraints: Solution Aadi AhlawatA freelance web developer with a decade … Read more

14. Longest Common Prefix Leetcode solution in JavaSctipt (js)

0 Problem Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string “”. Example 1: Input: strs = [“flower”,”flow”,”flight”] Output: “fl” Example 2: Input: strs = [“dog”,”racecar”,”car”] Output: “” Explanation: There is no common prefix among the input strings. Constraints: Solution … Read more

13. Roman to Integer Leetcode Solution in JavaScript (js)

0 Problem Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II. Roman … Read more

12. Integer to Roman Leetcode Solution in JavaScript (js)

0 Problem : Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one’s added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II. … Read more

11. Container With Most Water Leetcode JavaScript (JS) Solution

0 Problem You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not … Read more

10. Regular Expression Matching Leetcode solution in Javascript (JS)

0 Problem Given an input string s and a pattern p, implement regular expression matching with support for ‘.’ and ‘*’ where: The matching should cover the entire input string (not partial). Example 1: Input: s = “aa”, p = “a” Output: false Explanation: “a” does not match the entire string “aa”. Example 2: Input: s = “aa”, p = “a*” Output: true Explanation: … Read more

8. String to Integer (atoi) Leetcode Solution JavaScript (JS)

0 Problem Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++’s atoi function). The algorithm for myAtoi(string s) is as follows: Note: Example 1: Input: s = “42” Output: 42 Explanation: The underlined characters are what is read in, the caret is the current reader position. Step 1: “42” (no characters read because … Read more

7. Reverse Integer Leetcode Solution in JavaScript (JS)

0 Problem Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 – 1], then return 0. Assume the environment does not allow you to store 64-bit integers (signed or unsigned). Example 1: Input: x = 123 Output: 321 Example 2: Input: x = … Read more

5. Longest Palindromic Substring Leetcode Solution in JavaScript (JS)

0 Problem: Given a string s, return the longest  palindromic substring in s. Example 1: Input: s = “babad” Output: “bab” Explanation: “aba” is also a valid answer. Example 2: Input: s = “cbbd” Output: “bb” Constraints: Solution: Simple solution for beginners with separate function to check palindrome and code to create all possible substrings from a string. Aadi … Read more

Skip to content