Skip to content
nalar

Years of coding, still stuck on logic tests?

Nalar trains the thinking, not the syntax. Five-minute lessons animated from real code, made for your phone.

function solution(n) {  let count = 0  for (let i = 1; i < n; i++)    if (i % 3 === 0) count++  return count}

What does solution(10) return?

Daily work and logic tests train different muscles

You aren't short on experience. Logic tests just measure things your job rarely asks for.

Daily work trains

  • Wiring frameworks, APIs and libraries together
  • Finding answers in docs and example code
  • Debugging with logs and a debugger
  • Days to finish, and a team to review

Logic tests ask you to

  • Turn a short statement into steps
  • Trace a loop in your head, with no debugger
  • Find the edge case before the hidden tests do
  • Pick a pattern that fits the time limit

One lesson, one idea

Each lesson is 5 to 9 short steps, and most of them are taps. Here are three, taken from real lessons.

  1. 1/3 · Explanation

    Watch the code run

    The animation comes from code that really runs. Each step marks what changed.

    From lesson 4.4: Two sum with a map
    nums(4)
    1. 2
    2. 7
    3. 11
    4. 15
    need
    not set
    seen
    not set

    Call solution([2, 7, 11, 15], 9).

    1, line running nowfunction solution(nums, target) {
    2 const seen = new Map()
    3 for (let i = 0; i < nums.length; i++) {
    4 const need = target - nums[i]
    5 if (seen.has(need)) {
    6 return [seen.get(need), i]
    7 }
    8 seen.set(nums[i], i)
    9 }
    10}
  2. 2/3 · Predict the result

    Predict first, then run it

    You pick an answer, then the code runs. Every wrong choice gets its own explanation.

    From lesson 2.2: Loop boundaries

    Predict the output

    function solution(s) {  let out = ""  for (let i = 0; i <= s.length; i++) {    out += s[i]  }  return out}

    Notice the <=. What does it return for "abc"?

  3. 3/3 · Arrange the code

    Arrange the lines, tests decide

    You put shuffled lines of code back in order. Test cases check the result, like in a real test.

    From lesson 2.2: Loop boundaries
    1. function solution(nums) {
    2. const out = []
    3. for (let i = 0; i < nums.length - 1; i++) {
    4. out.push(nums[i] + nums[i + 1])
    5. }
    6. return out
    7. }

    Available lines. Not all of them belong.

    • for (let i = 0; i < nums.length; i++) {
    • for (let i = 1; i < nums.length - 1; i++) {

    Test cases

    • solution([1, 2, 3]) → [3, 5]
    • solution([2, 2]) → [4]
    • solution([5]) → []
    • solution([]) → []
    • solution([1, -1, 4, 0]) → [0, 3, 4]

What's in the course

It starts with how to read a problem, then the patterns that come up most. New modules come out one at a time.

Part 1 · How to think

  1. 1Read the problemBreak a problem into clear parts, work the examples by hand, hunt edge cases, then write a plan before the code.4 lessons + challenge
  2. 2Trace code in your headRun code in your head with a trace table. Learn loop boundaries, break, continue, early return, and the usual reasons tests fail.4 lessons + challenge
  3. 3Brute force firstTry every option first. Then count the steps, read the constraints, and find the work that gets repeated.4 lessons + challenge

Part 2 · Core patterns

  1. 4Hash map: count and look upUse Map and Set to count frequencies, find duplicates, check anagrams, and solve two sum in one pass.4 lessons + challenge
  2. 5Two pointerssoonTwo indexes moving toward each other or side by side. For reversing, palindromes, pair sums in a sorted array, and merging.
  3. 6Sliding windowsoonA window that slides over an array or string. Fixed size first, then windows that grow and shrink.
  4. 7Prefix sums and running statesoonKeep the result so far so you never recount. Running totals, best so far, and range sums.
  5. 8Sort firstsoonSort first, then scan once. Includes the JavaScript sort() number trap and simple intervals.

Part 3 · Structures and recursion

  1. 9Stack and queuesoonLast in, first out, or first in, first out. For matching brackets, undo, and next greater element.
  2. 10RecursionsoonA function that calls itself. Base case, call stack, recursion tree, and memo.
  3. 112D gridssoonArrays inside arrays. Row and column indexes, neighbors, flood fill, and rotating a grid.

Part 4 · Test day

  1. 12Mixed practicesoonMixed problems in test format. Name the pattern first, then solve it. No timer.

Good to know

Free
No signup and no account. Progress stays in this browser.
5 to 7 minutes
One lesson fits in a lunch break or a commute.
Works on a phone
Most steps are taps. Writing code is easier on a laptop, and you can skip it for later.
Indonesian and English
Every lesson comes in both languages.
JavaScript
All the code in this course is JavaScript, which you most likely use already.

Start with the first lesson

One short lesson, one idea: how to read a test problem before you write any code.