Skip to content

Commit 602a955

Browse files
authored
Merge pull request #620 from sir-gon/refactor
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: New Year …
2 parents eac33d4 + e8bc25b commit 602a955

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
*/
44

55
export const TOO_CHAOTIC_ERROR = 'Too chaotic';
6+
export const NEW_YEAR_CHAOS_TOLERANCE = 2;
67

78
export function minimumBribes(q: number[]): number {
89
let bribes = 0;
910
let i = 0;
1011

1112
q.forEach((value) => {
1213
const position = i + 1;
13-
if (value - position > 2) {
14+
if (value - position > NEW_YEAR_CHAOS_TOLERANCE) {
1415
throw new Error(TOO_CHAOTIC_ERROR);
1516
}
1617

17-
const fragment = q.slice(Math.max(value - 2, 0), i);
18+
const fragment = q.slice(Math.max(value - NEW_YEAR_CHAOS_TOLERANCE, 0), i);
1819

1920
fragment.forEach((k) => {
2021
if (k > value) {

0 commit comments

Comments
 (0)