You are not logged in. Please login at to post your questions!


CRANBROM - Editorial

Level: Medium

Concepts: Greedy,Dynamic programming, hashing

Problem link:

This one can be done in many ways. Here is an O(n) solution .

Below I will outline a way where we dynamically store whatever best so far we could have earned every time we find a broom.

Whenever we have a customer we will compare the current profit with the one will be making if we sell the broom being demanded.


//initialise an array l with -1 ans=0
for every day iterate: string,i=input();//take the input if string=='found': l[i]=ans else if l[i]>=0: ans=max(ans,l[i]+i) l[i]=-1 print ans

This question is marked "community wiki".

asked 11 Feb '14, 04:07

apoorv_j's gravatar image

accept rate: 0%

edited 12 Feb '14, 03:20

admin's gravatar image

0★admin ♦♦

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 11 Feb '14, 04:07

question was seen: 1,066 times

last updated: 12 Feb '14, 03:20