Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Language With isZero Output Sequence

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Language With isZero Output Sequence. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Study's learning interface uses a counter abstraction with only three operations: increment(), decrement(), and isZero(). Given a maximum digit and a repetition count, generate the repeating sequence 01234543210... without comparing counter values or using relational operators.

Return the generated digits as a string. Each repetition contains the values from 0 through maximum, followed by the values from maximum - 1 back to 0.

Formal Specification

Implement generate_wave(maximum, repetitions):

  • maximum is a non-negative integer specifying the peak digit.
  • repetitions is a non-negative integer specifying how many complete waves to emit.
  • Return a string containing all emitted digits.
  • Counter movement and loop termination must use only increment(), decrement(), and isZero().
  • Do not use <, >, <=, >=, equality checks, arithmetic on counter values, or conversion of a counter to an integer during the algorithm.

Constraints

  • 0 <= maximum <= 1000
  • 0 <= repetitions <= 1000
  • The output length is at most 2,001,000 characters
  • Counters are initialized with non-negative values
  • Counter control flow may use only increment(), decrement(), and isZero()

Function Signature

def generate_wave(maximum, repetitions):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output