0% found this document useful (0 votes)
6 views2 pages

JavaScript DSA Interview Cheat Sheet

This document is a JavaScript DSA interview cheat sheet that provides solutions for common coding problems such as reversing a string, checking for palindromes, and finding the maximum in an array. Each problem includes basic and optimized solutions along with their time complexities. It serves as a quick reference for interview preparation.

Uploaded by

ritikr389
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

JavaScript DSA Interview Cheat Sheet

This document is a JavaScript DSA interview cheat sheet that provides solutions for common coding problems such as reversing a string, checking for palindromes, and finding the maximum in an array. Each problem includes basic and optimized solutions along with their time complexities. It serves as a quick reference for interview preparation.

Uploaded by

ritikr389
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

■ JavaScript DSA Interview Cheat Sheet

Q: Reverse a String
■ Reverse 'hello' → 'olleh'
• ■ Basic: [Link]('').reverse().join('')
• ■ Optimized: Loop and build reversed string
• ■ Time Complexity: Basic: O(n), Optimized: O(n)

Q: Palindrome Check
■ Check if 'madam' is palindrome
• ■ Basic: Compare with reversed string
• ■ Optimized: Two pointers (left & right)
• ■ Time Complexity: Basic: O(n), Optimized: O(n)

Q: Find Maximum in Array


■ [3,7,2,9] → 9
• ■ Basic: [Link](...arr)
• ■ Optimized: Loop to track max
• ■ Time Complexity: Both: O(n)

Q: Count Character Occurrences


■ 'banana', 'a' → 3
• ■ Basic: Filter chars and count length
• ■ Optimized: Loop counter
• ■ Time Complexity: Both: O(n)

Q: Remove Duplicates
■ [1,2,2,3,4,4] → [1,2,3,4]
• ■ Basic: [...new Set(arr)]
• ■ Optimized: Manual loop with hash map
• ■ Time Complexity: Both: O(n)

Q: FizzBuzz
■ Multiples of 3 → Fizz, 5 → Buzz, 15 → FizzBuzz
• ■ Basic: If-else with modulo
• ■ Optimized: Same as basic (optimal)
• ■ Time Complexity: O(n)

Q: Two Sum
■ [2,7,11,15], target=9 → true
• ■ Basic: Nested loops (check all pairs)
• ■ Optimized: Hash set for complements
• ■ Time Complexity: Basic: O(n²), Optimized: O(n)
Q: Factorial
■ 5! = 120
• ■ Basic: Recursive solution
• ■ Optimized: Iterative loop
• ■ Time Complexity: Both: O(n)

Q: First Non-Repeating Character


■ 'swiss' → 'w'
• ■ Basic: Check indexOf vs lastIndexOf
• ■ Optimized: Use frequency map
• ■ Time Complexity: Basic: O(n²), Optimized: O(n)

Q: Anagram Check
■ 'listen', 'silent' → true
• ■ Basic: Sort and compare strings
• ■ Optimized: Frequency map comparison
• ■ Time Complexity: Basic: O(n log n), Optimized: O(n)

Q: Find Missing Number


■ [1,2,4,5], n=5 → 3
• ■ Basic: Check 1…n manually
• ■ Optimized: Use sum formula (n*(n+1)/2)
• ■ Time Complexity: Basic: O(n²), Optimized: O(n)

Q: Check for Duplicates


■ [1,2,3,1] → true
• ■ Basic: Nested loops
• ■ Optimized: Use Set to track
• ■ Time Complexity: Basic: O(n²), Optimized: O(n)

You might also like