joshmomel / algoexpert_ts Goto Github PK
View Code? Open in Web Editor NEWAlgoexpert Solutions
Algoexpert Solutions
As shown below, we need to find out the non-Constructible Change from giving list of coins
It makes sense to sort an array when we deal with array questions.
let's consider a single array [number] (number from 1 to infinity)
In this case, it will return 1 or number + 1
let's consider array [1,2]
It can generate:
[1] -> 1
[1, 2] -> 1, 2, 3
from | to | range |
[1] | 1 | [1] |
[1, 1] | 1, 2 | [1, 2] |
[1, 1, 2] | 1, 2, 2+1, 2+2 | [1, 4] |
[1, 1, 2, 5] | 1, 2, 3, 4, ..., 5, 5+1, 5+2, .. , 9(5+4) | [1, 9] |
[1, 1, 2, 5, 7] | 1, 2, 3, 4, ..., 7, 7+1, ..., 16(7+9) | [1, 16] |
[1, 1, 2, 5, 7, 22] | 1, 2, 3, 4, ..., 16, 22, 22+1 π€ Wait! 17 is missing | [1, 9] |
[1, ..., sum]
sum + 1
This task is to remove the duplicate node in the Linked list
π° In general, most tasks related to Linked list are about altering node.next.
In this task, we also need to come up with an approach to alter node.next, which ensures node.value NOT equal to node.next.vale
1 -> 1 -> 1 -> 2 -> 3 => 1 -> 3
So, it's not hard to think that we need an loop
while(...) {
if(!valueDuplicated) {
...
} else {
`alter node.next`
}
}
π¬ We can look ahead
Instead of checking linkedlist
is null as the while loop condition like below
while (currentNode) {
let nextNode = currentNode.next
while(currentNode.value === nextNode.value) {
nextNode = currentNode.next
}
currentNode.next = nextNode
currentNode = nextNode
}
We can check the next node like below
const list: Array<number> = [linkedList.value];
let pointer = linkedList
while (pointer.next) {
const v = pointer.next.value;
...
pointer.next = pointer.next.next
}
In summary, by looking ahead, pointer only move to the right place instead moving one by one. However, both approach have same complexity
Get the array of all permutations. i.e.
[1,2,3] => [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
**Let's start from some simple cases **
0 numbers [] => []
total = 0
1 numbers [1] => [1]
total = 1
2 numbers [1,2] => [1,2] [2,1]
total = 2 * 1 = 2
3 numbers [1,2,3] => [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
total = 3 * 2
n numbers [1,2,3...n] => [...]
total = n * total(n-1)
details
[1,2] can be seen as 2 insert into all positions of [1] (in the front and back) => [1,2] [2,1]
[1,2,3] can be seen as 3 insert into all positions of the Permutations [1,2], which includes
- 3 insert into all positions of [1,2] => [3,1,2],[1,3,2],[1,2,3]
- 3 insert into all positions of [2,1] => [3,2,1],[2,3,1],[2,1,3]
As discussed above, we can build the permutation from [].
let's assumed that we need to find the permutation of [1,2,3..n]
Sudo code can be
for eachNumber in n:
insert eachNumber into all positions of Permutation of [1..n-1]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.