-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52d87e2
commit c0ac049
Showing
13 changed files
with
127 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/page-16/1656. Design an Ordered Stream/OrderedStream.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Accepted | ||
*/ | ||
export class OrderedStream { | ||
stream: string[]; | ||
ptr = 0; | ||
|
||
constructor(n: number) { | ||
this.stream = Array(n); | ||
} | ||
|
||
insert(idKey: number, value: string): string[] { | ||
const chunk: string[] = []; | ||
|
||
this.stream[idKey - 1] = value; | ||
|
||
while (this.stream[this.ptr]) { | ||
chunk.push(this.stream[this.ptr]); | ||
this.ptr += 1; | ||
} | ||
|
||
return chunk; | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
src/page-16/1656. Design an Ordered Stream/ordered-stream.ts
This file was deleted.
Oops, something went wrong.
8 changes: 7 additions & 1 deletion
8
src/page-16/1678. Goal Parser Interpretation/interpret.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import { interpret } from './interpret'; | ||
import { interpret, interpret2 } from './interpret'; | ||
|
||
describe('1678. Goal Parser Interpretation', () => { | ||
test('interpret', () => { | ||
expect(interpret('G()(al)')).toBe('Goal'); | ||
expect(interpret('G()()()()(al)')).toBe('Gooooal'); | ||
expect(interpret('(al)G(al)()()G')).toBe('alGalooG'); | ||
}); | ||
|
||
test('interpret2', () => { | ||
expect(interpret2('G()(al)')).toBe('Goal'); | ||
expect(interpret2('G()()()()(al)')).toBe('Gooooal'); | ||
expect(interpret2('(al)G(al)()()G')).toBe('alGalooG'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,36 @@ | ||
type Interpret = (command: string) => string; | ||
|
||
export const interpret: Interpret = (command) => | ||
command.replace(/\(\)/g, 'o').replace(/\(al\)/g, 'al'); | ||
/** | ||
* Accepted | ||
*/ | ||
export const interpret: Interpret = (command) => { | ||
return command.replace(/\(\)/g, 'o').replace(/\(al\)/g, 'al'); | ||
}; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const interpret2: Interpret = (command) => { | ||
let result = ''; | ||
let i = 0; | ||
|
||
while (i < command.length) { | ||
if (command[i] === 'G') { | ||
result += 'G'; | ||
i += 1; | ||
} else if (command[i] === '(' && command[i + 1] === ')') { | ||
result += 'o'; | ||
i += 2; | ||
} else if ( | ||
command[i] === '(' && | ||
command[i + 1] === 'a' && | ||
command[i + 2] === 'l' && | ||
command[i + 3] === ')' | ||
) { | ||
result += 'al'; | ||
i += 4; | ||
} | ||
} | ||
|
||
return result; | ||
}; |
2 changes: 1 addition & 1 deletion
2
... of Unique Elements/sum-of-unique.test.ts → ...um of Unique Elements/sumOfUnique.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
src/page-16/1752. Check if Array Is Sorted and Rotated/check.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
type Check = (nums: number[]) => boolean; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const check: Check = (nums) => { | ||
const n = nums.length; | ||
|
||
let count = 0; | ||
|
||
for (let i = 0; i < nums.length; i++) { | ||
if (nums[i] > nums[(i + 1) % nums.length]) { | ||
for (let i = 0; i < n; i++) { | ||
if (nums[i] > nums[(i + 1) % n]) { | ||
count += 1; | ||
} | ||
|
||
if (count > 1) return false; | ||
} | ||
|
||
return count <= 1; | ||
return true; | ||
}; |
27 changes: 0 additions & 27 deletions
27
src/page-16/1758. Minimum Changes To Make Alternating Binary String/min-operations.ts
This file was deleted.
Oops, something went wrong.
8 changes: 1 addition & 7 deletions
8
...ting Binary String/min-operations.test.ts → ...ating Binary String/minOperations.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
import { minOperations, minOperations2 } from './min-operations'; | ||
import { minOperations } from './minOperations'; | ||
|
||
describe('1758. Minimum Changes To Make Alternating Binary String', () => { | ||
test('minOperations', () => { | ||
expect(minOperations('0100')).toBe(1); | ||
expect(minOperations('10')).toBe(0); | ||
expect(minOperations('1111')).toBe(2); | ||
}); | ||
|
||
test('minOperations2', () => { | ||
expect(minOperations2('0100')).toBe(1); | ||
expect(minOperations2('10')).toBe(0); | ||
expect(minOperations2('1111')).toBe(2); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
src/page-16/1758. Minimum Changes To Make Alternating Binary String/minOperations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
type MinOperations = (s: string) => number; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const minOperations: MinOperations = (s) => { | ||
let countPattern1 = 0; // Count for pattern '010101...' | ||
let countPattern2 = 0; // Count for pattern '101010...' | ||
|
||
for (let i = 0; i < s.length; i++) { | ||
// Character expected in pattern 1 | ||
const expectedCharPattern1 = i % 2 === 0 ? '0' : '1'; | ||
if (s[i] !== expectedCharPattern1) countPattern1 += 1; | ||
|
||
// Character expected in pattern 2 | ||
const expectedCharPattern2 = i % 2 === 0 ? '1' : '0'; | ||
if (s[i] !== expectedCharPattern2) countPattern2 += 1; | ||
} | ||
|
||
return Math.min(countPattern1, countPattern2); | ||
}; |