CodeChef October Long Challenge – Phone Prices -S10E

This video very clearly explains the problem statement , logic to solve the problem and also the correct code.

What is the problem statement?
In this question, we simply need to check whether an element in the array is strictly smaller than elements present at the previous 5 positions.

How to solve this problem?

Iterate from the end of the array, and using another loop check this condition for previous 5 elements.

The case which needs to be handled is when there are no previous 5 elements to compare with, that is for the indexes 0,1,2,3 and 4, we don’t have the previous 5 indexes. This can be simply checked by using if condition, If index-5 is less than 0 , in this case, start the second loop from 0 till index-1 and check for the condition.

Keep count of the elements that are satisfying the given condition and print the count.

This is the most basic and easy approach to solve this problem.

Learn coding with Experts :


By admin

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x