-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTheArray.html
More file actions
15 lines (13 loc) · 4.51 KB
/
TheArray.html
File metadata and controls
15 lines (13 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td>John has an array of <b>n</b> integers.
Each pair of neighboring elements differs by at most <b>d</b>.
The first and the last elements of the array are equal to <b>first</b> and <b>last</b>, respectively.
<br></br><br></br>
Brus does not know John's array.
He only knows <b>n</b>, <b>d</b>, <b>first</b> and <b>last</b>.
He wants to compute the maximal possible element John might have in his array.
<br></br><br></br>
You are given ints <b>n</b>, <b>d</b>, <b>first</b> and <b>last</b>.
Return the maximal possible element the array might contain.
</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>TheArray</td></tr><tr><td>Method:</td><td>find</td></tr><tr><td>Parameters:</td><td>int, int, int, int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int find(int n, int d, int first, int last)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td>    </td></tr><tr><td></td></tr><tr><td colspan="2"><h3>Notes</h3></td></tr><tr><td align="center" valign="top">-</td><td>The constraints given below guarantee that there will always be at least one array that matches the values Brus knows.</td></tr><tr><td align="center" valign="top">-</td><td>For the constraints given below, the correct answer will always fit into an int.</td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>n</b> will be between 2 and 1,000,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>d</b> will be between 0 and 1000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>first</b> will be between -1000 and 1000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>last</b> will be between -1000 and 1000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>|<b>first</b> - <b>last</b>| will be at most (n-1)*d.</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>3</pre></td></tr><tr><td><pre>5</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>4</pre></td></tr></table></td></tr><tr><td><pre>Returns: 7</pre></td></tr><tr><td><table><tr><td colspan="2">Only the second element of the array is unknown.
Its maximal valid value is 7.
</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>10</pre></td></tr><tr><td><pre>100</pre></td></tr><tr><td><pre>999</pre></td></tr><tr><td><pre>100</pre></td></tr></table></td></tr><tr><td><pre>Returns: 999</pre></td></tr><tr><td><table><tr><td colspan="2">Due to the limitations, the first element is the largest element of the array.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>1000000</pre></td></tr><tr><td><pre>0</pre></td></tr><tr><td><pre>474</pre></td></tr><tr><td><pre>474</pre></td></tr></table></td></tr><tr><td><pre>Returns: 474</pre></td></tr><tr><td><table><tr><td colspan="2">All elements of the array are equal.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>97</pre></td></tr><tr><td><pre>53</pre></td></tr><tr><td><pre>-92</pre></td></tr><tr><td><pre>441</pre></td></tr></table></td></tr><tr><td><pre>Returns: 2717</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">4)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>99</pre></td></tr><tr><td><pre>3</pre></td></tr><tr><td><pre>-743</pre></td></tr><tr><td><pre>-619</pre></td></tr></table></td></tr><tr><td><pre>Returns: -535</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr></table><p>This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. </p></body></html>