Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Flower Shop

Easy
0/40
573 upvotes
Asked in companies
ArcesiumCognizantGlobal Logic

Problem statement

Oasis visits a Florist Shop. Shop has N flowers each being of a specific type and every flower costs 1 unit.

You are given type of each flower in an array P = [p1,p2,...,pN]. If he buys a flower of type P’ , then he will get all flowers whose type lies between P’ to P’+4 (both inclusive) for free.

You need to find and print the price Oasis has to pay to buy all flowers.

Detailed explanation ( Input/output format, Notes, Images )
Constraints
1 <= N <= 10^5
0 <= pi <= 10^4
Sample Input
5
1 2 3 17 10
Sample Output
3
Full screen
Console