File tree Expand file tree Collapse file tree 5 files changed +16
-56
lines changed
src/hackerrank/interview_preparation_kit/arrays Expand file tree Collapse file tree 5 files changed +16
-56
lines changed Original file line number Diff line number Diff line change @@ -3,14 +3,14 @@ import { logger as console } from '../../../logger';
3
3
4
4
import TEST_CASES from './cruch_testcases_test.json' ;
5
5
6
- import { arrayManipulation } from './cruch_bruteforce' ;
6
+ import crush from './cruch_bruteforce' ;
7
7
8
8
describe ( 'arrays: crush (bruteforce) small cases' , ( ) => {
9
9
it ( 'arrayManipulation Test Cases' , ( ) => {
10
10
expect . assertions ( 3 ) ;
11
11
12
12
TEST_CASES . forEach ( ( test ) => {
13
- const answer = arrayManipulation ( test . n , test . queries ) ;
13
+ const answer = crush . arrayManipulation ( test . n , test . queries ) ;
14
14
15
15
console . debug (
16
16
`arrayManipulation(${ test . n } , ${ test . queries . toString ( ) } ) solution found: ${ answer } `
Original file line number Diff line number Diff line change 5
5
6
6
import { logger as console } from '../../../logger' ;
7
7
8
- export function arrayManipulation ( n : number , queries : number [ ] [ ] ) : number {
8
+ function arrayManipulation ( n : number , queries : number [ ] [ ] ) : number {
9
9
const LENGTH = n + 1 ;
10
10
const SURROGATE_VALUE = 0 ;
11
11
const result : number [ ] = Array < number > ( LENGTH ) . fill ( SURROGATE_VALUE ) ;
Original file line number Diff line number Diff line change @@ -3,14 +3,14 @@ import { logger as console } from '../../../logger';
3
3
4
4
import TEST_CASES from './cruch_testcases_test.json' ;
5
5
6
- import { arrayManipulation } from './cruch_optimized' ;
6
+ import crush from './cruch_optimized' ;
7
7
8
8
describe ( 'arrays: crush (optimized)' , ( ) => {
9
9
it ( 'arrayManipulation Test Cases' , ( ) => {
10
10
expect . assertions ( 3 ) ;
11
11
12
12
TEST_CASES . forEach ( ( test ) => {
13
- const answer = arrayManipulation ( test . n , test . queries ) ;
13
+ const answer = crush . arrayManipulation ( test . n , test . queries ) ;
14
14
15
15
console . debug (
16
16
`arrayManipulation(${ test . n } , ${ test . queries . toString ( ) } ) solution found: ${ answer } `
Original file line number Diff line number Diff line change 2
2
* @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/crush.md]]
3
3
*/
4
4
5
- export function arrayManipulation ( n : number , queries : number [ ] [ ] ) : number {
5
+ function arrayManipulation ( n : number , queries : number [ ] [ ] ) : number {
6
6
// why adding 2?
7
7
// first slot to adjust 1-based index and
8
8
// last slot for storing accumSum result
Original file line number Diff line number Diff line change 3
3
"title" : " Sample Test Case 0" ,
4
4
"n" : 5 ,
5
5
"queries" : [
6
- [
7
- 1 ,
8
- 2 ,
9
- 100
10
- ],
11
- [
12
- 2 ,
13
- 5 ,
14
- 100
15
- ],
16
- [
17
- 3 ,
18
- 4 ,
19
- 100
20
- ]
6
+ [1 , 2 , 100 ],
7
+ [2 , 5 , 100 ],
8
+ [3 , 4 , 100 ]
21
9
],
22
10
"expected" : 200
23
11
},
24
12
{
25
13
"title" : " Sample Test Case 1" ,
26
14
"n" : 10 ,
27
15
"queries" : [
28
- [
29
- 1 ,
30
- 5 ,
31
- 3
32
- ],
33
- [
34
- 4 ,
35
- 8 ,
36
- 7
37
- ],
38
- [
39
- 6 ,
40
- 9 ,
41
- 1
42
- ]
16
+ [1 , 5 , 3 ],
17
+ [4 , 8 , 7 ],
18
+ [6 , 9 , 1 ]
43
19
],
44
20
"expected" : 10
45
21
},
46
22
{
47
23
"title" : " Sample Test Case 3" ,
48
24
"n" : 10 ,
49
25
"queries" : [
50
- [
51
- 2 ,
52
- 6 ,
53
- 8
54
- ],
55
- [
56
- 3 ,
57
- 5 ,
58
- 7
59
- ],
60
- [
61
- 1 ,
62
- 8 ,
63
- 1
64
- ],
65
- [
66
- 5 ,
67
- 9 ,
68
- 15
69
- ]
26
+ [2 , 6 , 8 ],
27
+ [3 , 5 , 7 ],
28
+ [1 , 8 , 1 ],
29
+ [5 , 9 , 15 ]
70
30
],
71
31
"expected" : 31
72
32
}
You can’t perform that action at this time.
0 commit comments