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

×

hotels spoj O(n) solution

http://www.spoj.com/problems/HOTELS/ Is there any O(n) solution to this problem

asked 17 Jul '14, 08:12

pyush's gravatar image

4★pyush
311
accept rate: 0%


Using 2 pointers, pL and pR, tracing cost sum between pL..pR.

Initially pL=pR=1; if cost above limit, advance pL; otherwise advance pR.

Recording the maximum cost below M during the process. When pR > N, you get the global maximum.

link

answered 17 Jul '14, 08:42

tec's gravatar image

5★tec
304118
accept rate: 21%

i applied the same logic . But is there any better logic?

(17 Jul '14, 08:57) pyush4★

It is already O(n). what type of logic do you expect?

(17 Jul '14, 11:25) tec5★

can u please explain it using kadane's algorithm?

link

answered 20 Jun '15, 11:52

ankitkumar_95's gravatar image

4★ankitkumar_95
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×38

question asked: 17 Jul '14, 08:12

question was seen: 4,718 times

last updated: 20 Jun '15, 11:52