Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
Question 73

An activity tracking app records a user's daily activity as an array of binary values, daily_activity, where 1 represents an 'active' day and 0 represents an 'inactive' day.

Below is the pseudocode designed to find the length of the longest consecutive active streak (the maximum number of consecutive 1s) in the daily_activity array.

daily_activity ← USERINPUT
max_streak ← 0
current_streak ← 0
idx ← 0

WHILE idx < LEN(daily_activity)
    IF daily_activity[idx] == 1 THEN
        current_streak ← current_streak + 1
    ELSE
        IF current_streak > max_streak THEN
            max_streak ← current_streak
        ENDIF
        [LINE_Y]
    ENDIF
    idx ← idx + 1
ENDWHILE

IF current_streak > max_streak THEN
    max_streak ← current_streak
ENDIF

OUTPUT max_streak

Select one option to show what code should be written at point [LINE_Y].

A

current_streak←1current\_streak \leftarrow 1current_streak←1

B

max_streak←0max\_streak \leftarrow 0max_streak←0

C

current_streak←0current\_streak \leftarrow 0current_streak←0

D

idx←idx+1idx \leftarrow idx + 1idx←idx+1

Markscheme

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms

208 exam-style questions on AQA GCSE Computer Science Representing algorithms. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank