Skip to content
LearnStack
DSA curriculum

DSA practice

Short exercises. Try them first, open the hint if you are stuck, and the solution last.

  1. Exercise 1

    Reverse with a stack

    Use an array as a stack to reverse the string "queue" and print the result.

    Your solutionJavaScript
  2. Exercise 2

    First duplicate

    Write firstDuplicate(arr) that returns the first value seen twice, or -1. Use a Set so it is O(n).

    Your solutionJavaScript
  3. Exercise 3

    Balanced brackets

    Write isBalanced(s) for strings of ( and ). Return true when every ( is closed.

    Your solutionJavaScript