Company: Visa_29Aug

Difficulty: medium

Problem Statement

Script Execution with Nested Loops and Overflow Detection Problem Description You are handed a script written in a tiny toy language that manipulates a single variable y . The variable starts at zero and must always stay within the range 0 to 2 32 - 1. The language supports exactly three kinds of statements: foreach m : opens a loop whose body runs m times. terminate : closes the loop that was most recently opened and not yet closed. increment : adds 1 to y . After the whole script finishes, it reports the final value of y . Every foreach m is guaranteed to be matched with its own terminate , so the script is always well-formed. A loop body may be empty — that is, foreach m can be followed immediately by terminate — and an increment may appear outside of any loop. Watch out: enough repeated increments can push y past its allowed ceiling! Run the script starting from y = 0 and report whether the final value stays within bounds or overflows. If the final value of y would exceed 2 32 - 1,

More Visa_29Aug OA questionsInterview experiences