×

SAVPRSNR - Editorial

 0 PROBLEM LINK: Practice Author: Rupanjan Hari Tester: Rupanjan Hari DIFFICULTY : Easy PREREQUISITES : Math QUICK EXPLANATION Say there are N=5 prisoners and M=2 sweets. Distribution starts at ID number S=1, so prisoner 1 gets the first sweet and prisoner 2 gets the second (last) sweet. Thus, we must warn prisoner 2 about the poison, so we print 2 on a new line. EXPLANATION A simple formula drives the whole problem to the right direction by decreasing the complexity of the program to O(n) i.e. final=(S+(M%N)-1)%N; where the letters have their significance as per problem. This formula has to be applied for each input series. SOLUTION: click here to see the solution This question is marked "community wiki". asked 14 Oct '16, 12:05 4●1 accept rate: 0% 0★admin ♦♦ 19.8k●350●498●541
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×15,643
×3,748
×877
×214

question asked: 14 Oct '16, 12:05

question was seen: 836 times

last updated: 04 Jan '17, 13:53