Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

JavaScript Practice Questions (DSA)

This repository contains a comprehensive set of JavaScript practice problems designed to enhance problem-solving skills in various areas such as Conditional Statements & Loops, Functions, Strings, Arrays, and Objects. These questions are ideal for both beginners and experienced developers, covering common scenarios often encountered in coding interviews and real-world projects.

Conditional Statements & Loops

  1. Chessboard Pattern: Write a function that prints a chessboard pattern of size n x n using loops.
  2. Fibonacci Sequence: Generate the first n numbers in the Fibonacci sequence. Implement both iterative and recursive solutions.
  3. Kadane's Algorithm: Write a function that takes an array and returns the largest contiguous subarray sum using Kadane's Algorithm.

Functions

  1. Merge Arrays: Implement a function to merge multiple arrays into one using the spread operator.
  2. Callback Function: Write an example of a callback function that reads data and processes it asynchronously.

String Manipulation

  1. Reverse a String: Write a function reverseString(s) that takes a string s and returns its reverse.
  2. Check if String is Palindrome: Implement a function isPalindrome(s) to determine if a string reads the same forwards and backwards.
  3. Longest Palindromic Substring: Write a function longestPalindromicSubstring(s) that finds and returns the longest palindromic substring.
  4. Longest Common Prefix: Create a function longestCommonPrefix(strs) that takes an array of strings and returns the longest common prefix.
  5. Check Anagram: Implement a function isAnagram(s, t) to check if two strings are anagrams.
  6. Find All Anagrams in a String: Write a function findAllAnagrams(s, p) that finds all starting indices of p's anagrams in s.
  7. Longest Substring Without Repeating Characters: Write a function lengthOfLongestSubstring(s) to find the longest substring without repeating characters.
  8. String Rotation: Implement a function isRotation(s1, s2) that checks if s2 is a rotation of s1.
  9. Valid Parentheses: Write a function isValid(s) that checks if parentheses in a string are balanced.
  10. String Compression: Write a function compressString(s) that compresses a string by counting consecutive characters.
  11. Word Break Problem: Write a function wordBreak(s, wordDict) to determine if a string can be segmented into valid dictionary words.
  12. Substring with Concatenation of All Words: Write a function findSubstring(s, words) that finds all starting indices of substrings that are concatenations of all words in a list.
  13. Count and Say Problem: Implement the function countAndSay(n) to generate the nth term of the "count and say" sequence.
  14. Zigzag Conversion: Write a function convert(s, numRows) that converts a string into a zigzag pattern.
  15. Roman to Integer: Write a function romanToInt(s) to convert a Roman numeral to an integer.
  16. Integer to Roman: Implement a function intToRoman(num) to convert an integer to a Roman numeral.
  17. Add Binary Strings: Write a function addBinary(a, b) that adds two binary strings and returns the sum.
  18. Group Anagrams: Write a function groupAnagrams(strs) to group anagrams from an array of strings.
  19. Minimum Window Substring: Write a function minWindow(s, t) that finds the smallest window in s that contains all characters of t.
  20. First Non-Repeating Character: Write a function firstUniqChar(s) that returns the first non-repeating character in a string.

Arrays

  1. Find Missing Number: Given an array of integers from 1 to N, with one number missing, write a function to find the missing number.
  2. First Non-Repeating Element: Write a function to find the first non-repeating element in an array of integers.
  3. Merge Two Sorted Arrays: Merge two sorted arrays into one sorted array.
  4. Move Zeroes: Write a function that moves all zeroes in an array to the end while maintaining the order of other elements.
  5. Largest and Second Largest: Write a function to find the largest and second-largest elements in an array.
  6. Check for Duplicates: Write a function that checks if an array contains duplicate elements.
  7. Maximum Product: Find the maximum product of two integers in an array.
  8. Kadane’s Algorithm: Write a function to find the subarray with the largest sum.
  9. Rotate Array: Write a function to rotate an array by K steps.
  10. Sort 0s, 1s, and 2s: Implement the Dutch National Flag problem to sort an array of 0s, 1s, and 2s.
  11. Find Common Elements: Write a function to find the common elements between two unsorted arrays.
  12. Two Sum Problem: Write a function to find a pair of integers in an array that sum to a given target.
  13. Longest Subarray with Zero Sum: Find the length of the longest subarray with a sum of zero.
  14. Majority Element: Write a function to find the majority element in an array.
  15. Binary Search: Implement binary search on a sorted array.
  16. Array Intersection: Write a function to find the intersection of two arrays.
  17. Minimum Swaps to Sort: Write a function to find the minimum number of swaps required to sort an array.
  18. Missing Ranges: Write a function to find missing ranges in a sorted array.
  19. Subarrays Divisible by a Number: Find the number of subarrays with a sum divisible by a given number.
  20. Kth Largest Element: Write a function to find the kth largest element in an unsorted array.

Objects

  1. Deep Clone: Write a function to deep clone a JavaScript object.
  2. Merge Objects: Write a function that merges two objects into one.
  3. Check if Object is Empty: Write a function to check if an object has no properties.
  4. Object Comparison: Compare two objects to see if they have the same properties and values.
  5. Group Objects by Property: Write a function to group objects in an array by a specific property.
  6. Convert Object Keys to Array: Write a function that extracts all keys from an object and returns them in an array.
  7. Convert Object Values to Array: Write a function that extracts all values from an object and returns them in an array.
  8. Find Object by Property Value: Write a function to find an object in an array by a specific property value.
  9. Flatten a Nested Object: Write a function to flatten a deeply nested object.
  10. Access Nested Properties: Safely access properties in a deeply nested object using optional chaining.
  11. Count Property Occurrences: Write a function that counts the occurrence of a specific property value in an array of objects.
  12. Remove Property from Object: Write a function to delete a specific property from an object.
  13. Check Property Existence: Write a function that checks if a property exists in an object.
  14. Sort Array of Objects: Write a function to sort an array of objects based on a specific property.
  15. Freeze Object: Write a function that prevents any modifications to an object.
  16. Object to Query String: Write a function to convert an object’s properties into a URL query string.
  17. Dynamic Property Access: Write a function that dynamically accesses an object’s property using variables.
  18. Array of Objects to Single Object: Write a function that converts an array of objects into a single object using a property as the key.
  19. Find Max/Min Value in Object: Write a function to find the object with the maximum or minimum value for a specific property.
  20. Lookup Table: Write a function to convert an array of objects into a lookup table based on a specific property.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors