Workspace Largest Odd Number In String
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Largest Odd Number in String visualizer

Learn Largest Odd Number in String with a step-by-step Strings visualizer, JavaScript source code and a worked example. Practice fundamentals and parsing.

INTERACTIVE EXECUTION STUDIO
LEARN BY DOING

Predict. Execute. Understand.

Follow the source code, inspect live state changes, and predict the next operation before revealing it.

1 / 5Execution step
Reference example · JavaScript
Inspect reference input
"35420"

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
for(let i=a.length-1;
i>=0;
i--){
s("Find odd ending digit",{
Array:[...a]
},[i]);
if(+a[i]%2)return a.slice(0,i+1)
}
return ""
};

Execution canvas

Active Changed
STEP 1

Find odd ending digit

Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.

Array5 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Strings · Fundamentals and parsing

Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.

Example input

"35420"

Execution steps

  1. Find odd ending digit

Computed output

"35"
JavaScript reference implementation
const solve = (a,s)=>{
  for(let i=a.length-1;
  i>=0;
  i--){
    s("Find odd ending digit",{
      Array:[...a]
    },[i]);
    if(+a[i]%2)return a.slice(0,i+1)
  }
  return ""
};

Continue learning

Practice related DSA questions in the same topic.