FRIEZA - Editorial

PROBLEM LINKS:

Practice
Contest

Authors:

Anmol Rishi
Akshat Girdhar
Chirag Gupta

DIFFICULTY:

CakeWalk

PREREQUISITES:

Arrays, Strings

PROBLEM:

Iterate over the string and output the required digits.

EXPLANATION:

This is a simple problem in which we just have to iterate over the string and store the required digits in an array. You are given a string “frieza”(let it be called f) and each input will consist of a string(let’s assume it to be S). So now what you have to do is count continuous presence or non-presence of character from string f in S.

Step 1 - We first create a character array of length 6 and store the letters [f,r,i,e,z,a] in it. We also create an output array with size equal to the length of S. This is because the maximum size of the array will be equal to the length of string S (when S = “fdfdfdfdfdfdf…and so on”, output array will have elements = {1,1,1,1,1,1,1,… and so on}).

Step 2 - Loop to iterate over S. For each iteration, we check if the current letter belongs to the array [f,r,i,e,z,a] and increment a count variable accordingly. We also check if the previous letter also belonged to this array. If yes, then we increment the count, else we just save the count in the output array and increment its index.

Step 3 - We print the output array. We keep printing till the end of the array or until we get a zero.This is because when S=“freid” the array created will be {4,1,0,0,0}. And thus we have to stop printing as soon as we get a zero.

SOLUTION:

Java