How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focusโor scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
๐ง Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
๐ Select Passive to activate
Overview
You are given a 0-indexed integer arraynumswhere each element is a single digit between0and9(inclusive). The goal is to compute the triangular sum โ the single digit that remains after repeatedly transforming the array until only one element remains.
i with 0 <= i < n-1, use the expression newNums[i] = (nums[i] + nums[i+1]) % 10.% 10 at every step?% 10 keeps only the units (last) digit of each sum.(7 + 8) % 10 = 15 % 10 = 5.0โ9), matching the input domain.Input: nums = [1, 2, 3, 4, 5]
Step-by-step:
[1, 2, 3, 4, 5](1 + 2) % 10 = 3 โ first element(2 + 3) % 10 = 5 โ second element(3 + 4) % 10 = 7 โ third element(4 + 5) % 10 = 9 โ fourth element[3, 5, 7, 9](3 + 5) % 10 = 8(5 + 7) % 10 = 2 (12 % 10 = 2)(7 + 9) % 10 = 6 (16 % 10 = 6)[8, 2, 6](8 + 2) % 10 = 0 (10 % 10 = 0)(2 + 6) % 10 = 8 (8 % 10 = 8)[0, 8](0 + 8) % 10 = 8[8]โ
Result: The triangular sum for [1, 2, 3, 4, 5] is 8.
nums is an integer digit from 0 through 9. The modulo step preserves that range for all intermediate values.nums already has one element (e.g., nums = [5]), that element is the triangular sum.7 + 8 = 15), the tens place is dropped โ only 5 remains because 15 % 10 = 5.Return the single remaining digit (an integer 0โ9) after performing the repeated reductions. That value is the triangular sum of the input array.
๐ฏ Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
๐ Locked steps cannot be moved. Only unlocked steps are draggable.
๐ Enable sound for swap feedback and completion effects.