Connection Status:
Competition Arena > DevuAndRabbitNumbering
SRM 815 · 2021-10-06 · by praveen123 · Brute Force
Class Name: DevuAndRabbitNumbering
Return Type: String
Method Name: canRenumber
Arg Types: (vector<int>)
Problem Statement

Problem Statement

Devu loves rabbits a lot. He recently bought some rabbits from his friend Amit. Amit has given each rabbit an integer ID. These are given to you in the int[] rabbitIds.


Now, Devu knows that Amir is careless and sometimes assigns the same ID to multiple rabbits. To eliminate the possible confusion, Devu would like to make sure that no two rabbits have same ID.


Determine whether Devu can change all IDs into mutually distinct integers if he can only increase or decrease the ID of each rabbit by at most one. Return "can" (quotes for clarity) if he can do that, or "cannot" if he cannot make all IDs distinct without changing some of them by more than one.

Notes

  • The return value is case-sensitive.

Constraints

  • rabbitIds will contain between 1 and 50 elements, inclusive.
  • Each element of rabbitIds will be between 1 and 1000, inclusive.
Examples
0)
{1, 2, 3}
Returns: "can"

All the IDs of rabbits are already distinct.

1)
{1, 2, 2}
Returns: "can"

Devu can change the ID of the last rabbit to 3. Then all the rabbits will have distinct IDs.

2)
{2, 4, 2, 2, 1, 2}
Returns: "cannot"
3)
{1, 2, 4, 2, 6, 6, 7}
Returns: "can"
4)
{960,578,296,414,352,610,872,556,113,818,194,804,141,859,761,887,3,952,234,667,196,693,783}
Returns: "can"
30)
{37,15,24,26,34,20,16,35,21,18,7,3,22,13,40,5,45,47,46,14,32,19,42,33,10,36,23,31,9,38,41,1,8,43,49,17,12,4,29,48,30,44,6,50,27,2,39,25,28,11}
Returns: "can"

Array containing all elements from 1 to 50.

Submissions are judged against all 82 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class DevuAndRabbitNumbering with a public method string canRenumber(vector<int> rabbitIds) · 82 test cases · 2 s / 256 MB per case

Submitting as anonymous