Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Collection of interview questions with Unit Tests. Problems includes Data Struct
- [Minimum Stack](src/_DataStructures_/Stack/min-stack)
- [Balanced Parenthesis](src/_DataStructures_/Stack/balanced-parenthesis)
- [Postfix Expression Evaluation](src/_DataStructures_/Stack/postfix-expression-evaluation)

- [Remove Consecutive Repeated Digits](src/_DataStructures_/Stack/remove-consecutive-repeated-digits)
- [Implement 2 Stacks using Single Array](src/_DataStructures_/Stack/2-stacks-using1-array)


- [Queue](src/_DataStructures_/Queue)
- [Weave](src/_DataStructures_/Queue/weave)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Given an integer N, remove consecutive repeated digits from it.
* Input:133445
* Output:1345
*/

const Stack = require('../index');


function removeConsecutiveDigits(no) {
let s = new Stack();
let newNo = "";
//initally push first digit into stack
newNo += no[0];
s.push(no[0]);
for (let i = 1; i < no.length; i++) {
const digit = no[i];
//if stack top and incoming digit is same ignore it else append to newNo.
if (s.peek() !== digit) {
newNo += digit;
s.push(digit);
}
}
return newNo
}