Top 20 JavaScript related DSA question answers
Here’s a list of 20 popular JavaScript-related Data Structures and Algorithms (DSA) questions commonly asked in competitive programming, coding interviews, or during job applications. Along with each question, I’ve provided the solution in JavaScript.
1. Reverse a String
Problem: Reverse a given string.
2. Check for Palindrome
Problem: Check if a string is a palindrome.
3. Fibonacci Sequence
Problem: Find the nth Fibonacci number.
4. Find Factorial
Problem: Find the factorial of a number.
5. Sum of Natural Numbers
Problem: Find the sum of the first N natural numbers.
6. Binary Search
Problem: Perform binary search on a sorted array.
7. Merge Sort
Problem: Sort an array using merge sort.
8. Quick Sort
Problem: Sort an array using quick sort.
9. Merge Two Sorted Arrays
Problem: Merge two sorted arrays.
10. Two Sum
Problem: Find two numbers in an array that add up to a given target.
11. Reverse Linked List
Problem: Reverse a linked list.
12. Find Middle of Linked List
Problem: Find the middle element of a linked list.
13. Detect Cycle in Linked List
Problem: Detect if there is a cycle in a linked list.
14. Find Maximum Subarray (Kadane's Algorithm)
Problem: Find the maximum sum of a contiguous subarray.
15. Container With Most Water
Problem: Find the container with the most water.
16. Find All Anagrams in a String
Problem: Find all the start indices of p
's anagrams in s
.
17. Valid Parentheses
Problem: Check if the parentheses in a string are valid.
18. Find the Intersection of Two Arrays
Problem: Find the intersection of two arrays.
19. Rotate Image (Matrix)
Problem: Rotate an n x n
2D matrix 90 degrees.
20. Longest Substring Without Repeating Characters
Problem: Find the length of the longest substring without repeating characters.
Comments
Post a Comment