# The TransCompilator — Solved Programs · Chunk 04

Programs #0152–#0230 · 50 of 1,000 solved programs.

[Static catalog](https://ponvasanthpon.github.io/TransCompilator/problems/) · [llms.txt](https://ponvasanthpon.github.io/TransCompilator/llms.txt) · [Sitemap](https://ponvasanthpon.github.io/TransCompilator/sitemap.xml) · [Playground](https://ponvasanthpon.github.io/TransCompilator/)

Each entry contains the original natural-English `.eng` source and the
expected stdout. No LeetCode problem statement is copied.

---

## #0152 · Maximum Product Subarray

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0152) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0152.html)

```text
The numbers is a list of 2, 3, -2, and 4. The last is the last position of numbers. The high is item 0 of numbers. The low is item 0 of numbers. The best is item 0 of numbers.
For every spot from 1 to last.
The value is item spot of numbers. The first is high times value. The second is low times value. The top is first. If second is more than top, set top to second. If value is more than top, set top to value. The bottom is first. If second is less than bottom, set bottom to second. If value is less than bottom, set bottom to value. Set high to top. Set low to bottom. If high is more than best, set best to high.

Show best.
```

**Expected stdout**

```text
6
```

## #0153 · Find Minimum in Rotated Sorted Array

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0153) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0153.html)

```text
The numbers is a list of 3, 4, 5, 1, and 2. The smallest is item 0 of numbers.
For each value in numbers.
If value is less than smallest, set smallest to value.

Show smallest.
```

**Expected stdout**

```text
1
```

## #0154 · Find Minimum in Rotated Sorted Array II

**Hard · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0154) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0154.html)

```text
The numbers is a list of 2, 2, 2, 0, and 1. The smallest is item 0 of numbers.
For each value in numbers.
If value is less than smallest, set smallest to value.

Show smallest.
```

**Expected stdout**

```text
0
```

## #0160 · Intersection of Two Linked Lists

**Easy · Two Pointers** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0160) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0160.html)

```text
The values is a list of 4, 1, 8, 4, 5, 5, 6, and 1. The nexts is a list of 1, 2, 3, 4, -1, 6, 7, and 2. The first is 0. The second is 5. The firstsize is 0. The secondsize is 0. The node is 0.
Repeat while node is at least 0.
Add 1 to firstsize. Set node to item node of nexts.

Set node to 5.
Repeat while node is at least 0.
Add 1 to secondsize. Set node to item node of nexts.

Repeat while firstsize is more than secondsize.
Set first to item first of nexts. Subtract 1 from firstsize.

Repeat while secondsize is more than firstsize.
Set second to item second of nexts. Subtract 1 from secondsize.

Repeat while first is not second.
Set first to item first of nexts. Set second to item second of nexts.

Show item first of values.
```

**Expected stdout**

```text
8
```

## #0162 · Find Peak Element

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0162) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0162.html)

```text
The numbers is a list of 1, 2, 3, and 1. The last is the last position of numbers. The peak is 0.
For every spot from 0 to last.
The higherleft is 1. The higherright is 1. If spot is more than 0 and item (spot minus 1) of numbers is at least item spot of numbers, set higherleft to 0. If spot is less than last and item (spot plus 1) of numbers is at least item spot of numbers, set higherright to 0. If higherleft is 1 and higherright is 1, set peak to spot.

Show peak.
```

**Expected stdout**

```text
2
```

## #0164 · Maximum Gap

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0164) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0164.html)

```text
The numbers is a list of 3, 6, 9, and 1. Sort numbers. The last is the last position of numbers. The best is 0.
For every spot from 1 to last.
The gap is item spot of numbers minus item (spot minus 1) of numbers. If gap is more than best, set best to gap.

Show best.
```

**Expected stdout**

```text
3
```

## #0165 · Compare Version Numbers

**Medium · String** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0165) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0165.html)

```text
Keep a shared current as empty text. Keep a shared value of 0. Keep a shared foundat of 0. Keep a shared leftvalue of 0. Keep a shared rightvalue of 0. Keep a shared lastfirst of 0. Keep a shared lastsecond of 0. Keep a shared firsts as an empty list of text. Keep a shared seconds as an empty list of text.
To parse from spot (a whole number) with finish (a whole number). If spot is more than finish, return. The digit is the digit value of character spot of current. Set value to value times 10 plus digit. Parse from spot plus 1 with finish.

To parse segment. The finish is the last position of current. Parse from 0 with finish.

To read left at spot (a whole number). If spot is more than lastfirst, return. Set current to item spot of firsts. Set value to 0. Parse segment. Set leftvalue to value.

To read right at spot (a whole number). If spot is more than lastsecond, return. Set current to item spot of seconds. Set value to 0. Parse segment. Set rightvalue to value.

The first is "1.01". The second is "1.001". The firstparts is split first by ".". The secondparts is split second by ".".
For each part in firstparts.
Place part into firsts.

For each part in secondparts.
Place part into seconds.

The endfirst is the last position of firsts. The endsecond is the last position of seconds. Set lastfirst to endfirst. Set lastsecond to endsecond. The result is 0.
For every spot from 0 to 2.
Set leftvalue to 0. Set rightvalue to 0. If spot is at most lastfirst, read left at spot. If spot is at most lastsecond, read right at spot. If result is 0 and leftvalue is less than rightvalue, set result to -1. If result is 0 and leftvalue is more than rightvalue, set result to 1.

Show result.
```

**Expected stdout**

```text
0
```

## #0166 · Fraction to Recurring Decimal

**Medium · String** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0166) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0166.html)

```text
Keep a shared seen as an empty list of whole numbers. Keep a shared digits as an empty list of text. Keep a shared foundat of 0.
To find from spot (a whole number) with target (a whole number). If spot is more than the last position of seen, return. If item spot of seen is target, set foundat to spot, return. Find from spot plus 1 with target.

The numerator is 1. The denominator is 6. The sign is 1. If numerator is less than 0, set sign to -1. The top is numerator times sign. The bottom is denominator. The whole is top divided by bottom. The remainder is top modulo bottom. The result is format whole number whole as text. If sign is -1, The mark is empty text, Place "-" into mark, Place mark into result. The cycle is -1. If remainder is more than 0, Place "." into result.
Repeat while remainder is more than 0.
Set foundat to -1. Find from 0 with remainder. If foundat is at least 0, set cycle to foundat, break. Place remainder into seen. The digit is remainder times 10 divided by bottom. The piece is format whole number digit as text. Place piece into digits. Set remainder to remainder times 10 modulo bottom.

The lastdigit is the last position of digits.
For every spot from 0 to lastdigit.
If spot is cycle, Place "(" into result. Place item spot of digits into result.

If cycle is at least 0, Place ")" into result. Show result.
```

**Expected stdout**

```text
0.1(6)
```

## #0167 · Two Sum II - Input Array Is Sorted

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0167) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0167.html)

```text
The numbers is a list of 2, 7, 11, and 15. The target is 9. The left is 0. The right is 3. The answers is an empty list of whole numbers.
Repeat while left is less than right.
The sum is item left of numbers plus item right of numbers. If sum is target, Place left plus 1 into answers, Place right plus 1 into answers, break. If sum is less than target, add 1 to left. If sum is more than target, subtract 1 from right.

For each answer in answers, show answer.
```

**Expected stdout**

```text
1
2
```

## #0168 · Excel Sheet Column Title

**Easy · String** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0168) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0168.html)

```text
The value is 28. The alphabet is "ABCDEFGHIJKLMNOPQRSTUVWXYZ". The reversed is empty text.
Repeat while value is more than 0.
Subtract 1 from value. The digit is value modulo 26. Place character digit of alphabet into reversed. Set value to value divided by 26.

The last is the last position of reversed. The result is empty text.
For every step from 0 to last.
The source is last minus step. Place character source of reversed into result.

Show result.
```

**Expected stdout**

```text
AB
```

## #0169 · Majority Element

**Easy · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0169) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0169.html)

```text
The numbers is a list of 2, 2, 1, 1, 1, 2, and 2. The candidate is item 0 of numbers. The score is 0.
For each value in numbers.
If score is 0, set candidate to value. If value is candidate, add 1 to score. If value is not candidate, subtract 1 from score.

Show candidate.
```

**Expected stdout**

```text
2
```

## #0171 · Excel Sheet Column Number

**Easy · String** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0171) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0171.html)

```text
Keep a shared alphabet as empty text. Keep a shared foundat of 0. Place "ABCDEFGHIJKLMNOPQRSTUVWXYZ" into alphabet.
To locate from spot (a whole number) with symbol (a whole number). If spot is more than 25, return. If symbol is character spot of alphabet, set foundat to spot, return. Locate from spot plus 1 with symbol.

The name is "AB". The last is the last position of name. The value is 0.
For every spot from 0 to last.
Set foundat to -1. Locate from 0 with character spot of name. Set value to value times 26 plus foundat plus 1.

Show value.
```

**Expected stdout**

```text
28
```

## #0172 · Factorial Trailing Zeroes

**Medium · Math** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0172) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0172.html)

```text
The number is 25. The value is number. The count is 0.
Repeat while value is more than 0.
Set value to value divided by 5. Add value to count.

Show count.
```

**Expected stdout**

```text
6
```

## #0174 · Dungeon Game

**Hard · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0174) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0174.html)

```text
The dungeon is a list of -2, -3, 3, -5, -10, 1, 10, 30, and -5. The rows is a list of 2, 2, 2, 1, 1, 1, 0, 0, and 0. The columns is a list of 2, 1, 0, 2, 1, 0, 2, 1, and 0. The health is a list of 9 zeros.
For every step from 0 to 8.
The row is item step of rows. The column is item step of columns. The index is row times 3 plus column. The need is 1000000. If row is less than 2, set need to item (index plus 3) of health. If column is less than 2 and item (index plus 1) of health is less than need, set need to item (index plus 1) of health. If row is 2 and column is 2, set need to 1. The here is need minus item index of dungeon. If here is less than 1, set here to 1. Set item index of health to here.

Show item 0 of health.
```

**Expected stdout**

```text
7
```

## #0179 · Largest Number

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0179) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0179.html)

```text
Keep a shared parts as an empty list of text. Keep a shared keytext as empty text. Keep a shared front as empty text. Keep a shared back as empty text. The numbers is a list of 3, 30, 34, 5, and 9.
For each number in numbers.
The piece is format whole number number as text. Place piece into parts.

To shift from spot (a whole number) with marker (a whole number). If spot is less than 0, set item 0 of parts to keytext, return. The other is item spot of parts. Set front to empty text. Place other into front. Place keytext into front. Set back to empty text. Place keytext into back. Place other into back. If front comes before back, set item (spot plus 1) of parts to other, shift from spot minus 1 with marker, return. Set item (spot plus 1) of parts to keytext.

The last is 4.
For every spot from 1 to last.
Set keytext to item spot of parts. Shift from spot minus 1 with 0.

The result is join parts with "". Show result.
```

**Expected stdout**

```text
9534330
```

## #0187 · Repeated DNA Sequences

**Medium · String** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0187) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0187.html)

```text
Keep a shared source as empty text. Keep a shared windows as an empty list of text. Keep a shared target as empty text. Keep a shared tally of 0. Keep a shared already of 0. Keep a shared limit of 0. Place "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT" into source.
To count from spot (a whole number) with word (a whole number). If spot is more than the last position of windows, return. If item spot of windows matches target, add 1 to tally. Count from spot plus 1 with word.

To earlier from spot (a whole number) with word (a whole number). If spot is more than limit, return. If item spot of windows matches target, set already to 1, return. Earlier from spot plus 1 with word.

The last is 30. The finishstart is last minus 9.
For every start from 0 to finishstart.
The finish is start plus 10. The piece is the slice of source from start to finish. Place piece into windows.

The lastwindow is the last position of windows.
For every spot from 0 to lastwindow.
Set target to item spot of windows. Set tally to 0. Set already to 0. Set limit to spot minus 1. Count from 0 with 0. Earlier from 0 with 0. If tally is more than 1 and already is 0, show target.
```

**Expected stdout**

```text
AAAAACCCCC
CCCCCAAAAA
```

## #0188 · Best Time to Buy and Sell Stock IV

**Hard · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0188) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0188.html)

```text
Keep a shared buy as an empty list of whole numbers. Keep a shared sell as an empty list of whole numbers. Keep a shared deals of 2.
For every spot from 0 to 2.
Place 0 into buy. Place 0 into sell.

Set item 1 of buy to -1000000. Set item 2 of buy to -1000000.
To revise from deal (a whole number) with price (a whole number). If deal is more than deals, return. The trial is item (deal minus 1) of sell minus price. If trial is more than item deal of buy, set item deal of buy to trial. The trial is item deal of buy plus price. If trial is more than item deal of sell, set item deal of sell to trial. Revise from deal plus 1 with price.

The prices is a list of 3, 2, 6, 5, 0, and 3.
For each price in prices.
Revise from 1 with price.

The lastdeal is deals. Show item lastdeal of sell.
```

**Expected stdout**

```text
7
```

## #0189 · Rotate Array

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0189) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0189.html)

```text
The numbers is a list of 1, 2, 3, 4, 5, 6, and 7. The size is 7. The turn is 3. The offset is turn modulo size. The result is an empty list of whole numbers.
For every spot from 0 to 6.
The source is spot plus size minus offset. If source is at least size, set source to source minus size. Place item source of numbers into result.

For each value in result, show value.
```

**Expected stdout**

```text
5
6
7
1
2
3
4
```

## #0190 · Reverse Bits

**Easy · Bit Manipulation** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0190) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0190.html)

```text
The number is 43261596. The value is number. The result is 0.
For every step from 1 to 32.
The bit is bitwise and of value and 1. Set result to shift result left by 1. Set result to bitwise or of result and bit. Set value to shift value right by 1.

Show result.
```

**Expected stdout**

```text
964176192
```

## #0191 · Number of 1 Bits

**Easy · Bit Manipulation** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0191) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0191.html)

```text
The number is 11. The value is number. The count is 0.
Repeat while value is more than 0.
The bit is bitwise and of value and 1. Add bit to count. Set value to shift value right by 1.

Show count.
```

**Expected stdout**

```text
3
```

## #0198 · House Robber

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0198) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0198.html)

```text
The houses is a list of 1, 2, 3, and 1. The before is 0. The recent is 0.
For each value in houses.
The current is recent. The offered is before plus value. If offered is more than current, set current to offered. Set before to recent. Set recent to current.

Show recent.
```

**Expected stdout**

```text
4
```

## #0199 · Binary Tree Right Side View

**Medium · Depth-First Search** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0199) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0199.html)

```text
Keep a shared values holding 1, 2, 3, -1, 5, -1, and 4. Keep a shared lefts holding 1, 3, 5, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, -1, -1, -1, and -1.

The queue is an empty list of whole numbers. Place 0 into queue. The head is 0. The count is 1. The remaining is 1. The nextcount is 0.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. If item node of lefts is at least 0, Place item node of lefts into queue, add 1 to count, add 1 to nextcount. If item node of rights is at least 0, Place item node of rights into queue, add 1 to count, add 1 to nextcount. Subtract 1 from remaining. If remaining is 0, show item node of values, set remaining to nextcount, set nextcount to 0.
```

**Expected stdout**

```text
1
3
4
```

## #0200 · Number of Islands

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0200) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0200.html)

```text
The chart is a list of 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, and 0. Keep a shared land as an empty list of whole numbers.
For each square in chart.
Place square into land.

Keep a shared visited as an empty list of whole numbers.
For every spot from 0 to 19.
Place 0 into visited.

To walk from node (a whole number). If item node of land is 0, return. If item node of visited is 1, return. Set item node of visited to 1. The row is node divided by 5. The column is node modulo 5. If row is more than 0, walk from node minus 5. If row is less than 3, walk from node plus 5. If column is more than 0, walk from node minus 1. If column is less than 4, walk from node plus 1.

The islands is 0.
For every node from 0 to 19.
If item node of land is 1 and item node of visited is 0, add 1 to islands. If item node of land is 1 and item node of visited is 0, walk from node.

Show islands.
```

**Expected stdout**

```text
1
```

## #0201 · Bitwise AND of Numbers Range

**Medium · Bit Manipulation** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0201) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0201.html)

```text
The left is 5. The right is 7. The result is left.
For every value from left plus 1 to right.
Set result to bitwise and of result and value.

Show result.
```

**Expected stdout**

```text
4
```

## #0202 · Happy Number

**Easy · Math** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0202) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0202.html)

```text
Keep a shared value of 0. Keep a shared total of 0.
To digitize. Set total to 0.
Repeat while value is more than 0.
The digit is value modulo 10. Increase total by digit times digit. Set value to value divided by 10.

The start is 19. Set value to start. The steps is 0.
Repeat while value is more than 1 and steps is less than 100.
Digitize. Set value to total. Add 1 to steps.

If value is 1, show true, otherwise show false.
```

**Expected stdout**

```text
true
```

## #0203 · Remove Linked List Elements

**Easy · Linked List** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0203) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0203.html)

```text
The nodes is a list of 1, 2, 6, 3, 4, 5, and 6. The target is 6. The kept is an empty list of whole numbers.
For each value in nodes.
If value is not target, Place value into kept.

For each value in kept, show value.
```

**Expected stdout**

```text
1
2
3
4
5
```

## #0204 · Count Primes

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0204) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0204.html)

```text
The flags is a list of 10 zeros.
For every spot from 0 to 9.
Set item spot of flags to 1.

Set item 0 of flags to 0. Set item 1 of flags to 0.
For every base from 2 to 9.
If item base of flags is 1.
The multiple is base times base.
Repeat while multiple is less than 10.
Set item multiple of flags to 0. Increase multiple by base.

The count is 0.
For every spot from 2 to 9.
If item spot of flags is 1, add 1 to count.

Show count.
```

**Expected stdout**

```text
4
```

## #0205 · Isomorphic Strings

**Easy · String** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0205) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0205.html)

```text
Keep a shared source as empty text. Keep a shared targetcode of 0. Keep a shared located of 0.
To locate from spot (a whole number). If spot is more than the last position of source, return. If character spot of source is targetcode, set located to spot, return. Locate from spot plus 1.

The first is "egg". The second is "add". The copyfirst is a copy of first. The copysecond is a copy of second. The last is the last position of first. The valid is 1. Set source to copyfirst.
For every spot from 0 to last.
Set source to copyfirst. Set targetcode to character spot of first. Set located to -1. Locate from 0. The leftindex is located. Set source to copysecond. Set targetcode to character spot of second. Set located to -1. Locate from 0. The rightindex is located. If leftindex is not rightindex, set valid to 0.

If valid is 1, show true, otherwise show false.
```

**Expected stdout**

```text
true
```

## #0206 · Reverse Linked List

**Easy · Linked List** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0206) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0206.html)

```text
The nodes is a list of 1, 2, 3, 4, and 5. The last is the last position of nodes.
For every step from 0 to last.
The spot is last minus step. Show item spot of nodes.
```

**Expected stdout**

```text
5
4
3
2
1
```

## #0207 · Course Schedule

**Medium · Depth-First Search** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0207) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0207.html)

```text
The size is 2. The edges is a list of 1 and 0. The pairs is 1. The adjacency is a list of 4 zeros. The indegree is a list of 2 zeros.
For every edge from 0 to pairs minus 1.
The target is item (edge times 2) of edges. The origin is item (edge times 2 plus 1) of edges. Set item (origin times size plus target) of adjacency to 1. Increase item target of indegree by 1.

The queue is an empty list of whole numbers. The count is 0. The head is 0.
For every node from 0 to size minus 1.
If item node of indegree is 0, Place node into queue, add 1 to count.

The seen is 0.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. Add 1 to seen.
For every next from 0 to size minus 1.
If item (node times size plus next) of adjacency is 1.
Decrease item next of indegree by 1. If item next of indegree is 0, Place next into queue, add 1 to count.

If seen is size, show true, otherwise show false.
```

**Expected stdout**

```text
true
```

## #0209 · Minimum Size Subarray Sum

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0209) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0209.html)

```text
The target is 7. The numbers is a list of 2, 3, 1, 2, 4, and 3. The last is the last position of numbers. The best is 1000000.
For every start from 0 to last.
The total is 0.
For every finish from start to last.
Increase total by item finish of numbers.
If total is at least target.
The length is finish minus start plus 1. If length is less than best, set best to length. Break.

If best is 1000000, set best to 0. Show best.
```

**Expected stdout**

```text
2
```

## #0210 · Course Schedule II

**Medium · Depth-First Search** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0210) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0210.html)

```text
The size is 4. The edges is a list of 1, 0, 2, 0, 3, 1, 3, and 2. The pairs is 4. The adjacency is a list of 16 zeros. The indegree is a list of 4 zeros.
For every edge from 0 to pairs minus 1.
The target is item (edge times 2) of edges. The origin is item (edge times 2 plus 1) of edges. Set item (origin times size plus target) of adjacency to 1. Increase item target of indegree by 1.

The queue is an empty list of whole numbers. The count is 0. The head is 0.
For every node from 0 to size minus 1.
If item node of indegree is 0, Place node into queue, add 1 to count.

The order is an empty list of whole numbers.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. Place node into order.
For every next from 0 to size minus 1.
If item (node times size plus next) of adjacency is 1.
Decrease item next of indegree by 1. If item next of indegree is 0, Place next into queue, add 1 to count.

For each value in order, show value.
```

**Expected stdout**

```text
0
1
2
3
```

## #0212 · Word Search II

**Hard · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0212) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0212.html)

```text
Keep a shared grid as empty text. Keep a shared current as empty text. Keep a shared visited as an empty list of whole numbers. Keep a shared found of 0. Keep a shared limit of 0.
To wipe from spot (a whole number). If spot is more than 15, return. Set item spot of visited to 0. Wipe from spot plus 1.

To search from row (a whole number) at column (a whole number) with index (a whole number). If found is 1, return. If row is less than 0 or row is more than 3 or column is less than 0 or column is more than 3, return. The node is row times 4 plus column. If item node of visited is 1, return. If character node of grid is not character index of current, return. If index is limit, set found to 1, return. Set item node of visited to 1. If found is 0, search from row plus 1 at column with index plus 1. If found is 0, search from row minus 1 at column with index plus 1. If found is 0, search from row at column plus 1 with index plus 1. If found is 0, search from row at column minus 1 with index plus 1. Set item node of visited to 0.

To seek from node (a whole number). If node is more than 15, return. If found is 1, return. The row is node divided by 4. The column is node modulo 4. Search from row at column with 0. Seek from node plus 1.

The board is "oaanetaeihkriflv". The gridcopy is a copy of board. Set grid to gridcopy. The words is "oath,pea,eat,rain". The items is split words by ",". The answers is an empty list of text.
For every spot from 0 to 15.
Place 0 into visited.

For each word in items.
The copy is a copy of word. Set current to copy. The final is the last position of current. Set limit to final. Set found to 0. Wipe from 0. Seek from 0. If found is 1, Place copy into answers.

The total is the number of items in answers. The last is total minus 1.
For every left from 0 to last.
For every right from left to last.
If item right of answers comes before item left of answers, swap item left of answers and item right of answers.

For each answer in answers, show answer.
```

**Expected stdout**

```text
eat
oath
```

## #0213 · House Robber II

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0213) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0213.html)

```text
The nums is a list of 2, 3, and 2. Keep a shared houses as an empty list of whole numbers.
For each value in nums.
Place value into houses.

Keep a shared take of 0. Keep a shared skip of 0. Keep a shared best of 0.
To rob from spot (a whole number) with finish (a whole number). If spot is more than finish, return. The current is skip. The offered is take plus item spot of houses. If offered is more than current, set current to offered. Set take to skip. Set skip to current. Rob from spot plus 1 with finish.

Set best to 0. Set take to 0. Set skip to 0. Rob from 0 with 1. Set best to skip. Set take to 0. Set skip to 0. Rob from 1 with 2. If skip is more than best, set best to skip.

Show best.
```

**Expected stdout**

```text
3
```

## #0214 · Shortest Palindrome

**Hard · String** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0214) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0214.html)

```text
Keep a shared word as empty text. Keep a shared pal of 0.
To test from left (a whole number) with right (a whole number). If left is at least right, return. If character left of word is not character right of word, set pal to 0, return. Test from left plus 1 with right minus 1.

The source is "aacecaaa". The copy is a copy of source. Set word to copy. The last is the last position of source. The best is 1.
For every step from 0 to last.
The length is last plus 1 minus step. The right is length minus 1. Set pal to 1. Test from 0 with right. If pal is 1, set best to length, break.

The front is empty text. The count is last plus 1 minus best.
For every step from 0 to count minus 1.
The spot is last minus step. Place character spot of source into front.

The result is a copy of front.
For every spot from 0 to last.
Place character spot of source into result.

Show result.
```

**Expected stdout**

```text
aaacecaaa
```

## #0215 · Kth Largest Element in an Array

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0215) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0215.html)

```text
The numbers is a list of 3, 2, 1, 5, 6, and 4. The rank is 2. The last is the last position of numbers.
For every left from 0 to last.
For every right from left plus 1 to last.
If item right of numbers is more than item left of numbers, swap item left of numbers and item right of numbers.

The spot is rank minus 1. Show item spot of numbers.
```

**Expected stdout**

```text
5
```

## #0216 · Combination Sum III

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0216) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0216.html)

```text
Keep a shared parts as an empty list of text. Keep a shared answers as an empty list of text. Keep a shared choose of 0. Keep a shared target of 0. Set choose to 3. Set target to 7.
To shape from start (a whole number) at depth (a whole number) with total (a whole number). If depth is choose and total is target, The built is join parts with ",", Place built into answers, return. If depth is choose, return. If total is more than target, return.
For every value from start to 9.
If total plus value is at most target.
The piece is format whole number value as text. Place piece into parts. Shape from value plus 1 at depth plus 1 with total plus value. Remove the last item from parts.

Shape from 1 at 0 with 0. For each answer in answers, show answer.
```

**Expected stdout**

```text
1,2,4
```

## #0217 · Contains Duplicate

**Easy · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0217) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0217.html)

```text
The numbers is a list of 1, 2, 3, and 1. The last is the last position of numbers. The found is 0.
For every left from 0 to last.
For every right from left plus 1 to last.
If item left of numbers is item right of numbers, set found to 1.

If found is 1, show true, otherwise show false.
```

**Expected stdout**

```text
true
```

## #0218 · The Skyline Problem

**Hard · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0218) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0218.html)

```text
The lefts is a list of 2, 3, 5, 15, and 19. The rights is a list of 9, 7, 12, 20, and 24. The highs is a list of 10, 15, 12, 10, and 8. The sky is a list of 25 zeros. The total is 5.
For every building from 0 to total minus 1.
The left is item building of lefts. The right is item building of rights. The high is item building of highs.
For every spot from left to right minus 1.
If item spot of sky is less than high, set item spot of sky to high.

The previous is 0.
For every spot from 0 to 24.
The current is item spot of sky. If current is not previous, Report spot, Report current, Report "---", set previous to current.
```

**Expected stdout**

```text
2
10
---
3
15
---
7
12
---
12
0
---
15
10
---
20
8
---
24
0
---
```

## #0219 · Contains Duplicate II

**Easy · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0219) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0219.html)

```text
The numbers is a list of 1, 2, 3, and 1. The distance is 3. The last is the last position of numbers. The found is 0.
For every left from 0 to last.
For every right from left plus 1 to last.
The gap is right minus left. If gap is at most distance and item left of numbers is item right of numbers, set found to 1.

If found is 1, show true, otherwise show false.
```

**Expected stdout**

```text
true
```

## #0220 · Contains Duplicate III

**Hard · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0220) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0220.html)

```text
The numbers is a list of 1, 2, 3, and 1. The indexgap is 3. The valuegap is 0. The last is the last position of numbers. The found is 0.
For every left from 0 to last.
For every right from left plus 1 to last.
The gap is right minus left. The difference is item left of numbers minus item right of numbers. If difference is less than 0, set difference to 0 minus difference. If gap is at most indexgap and difference is at most valuegap, set found to 1.

If found is 1, show true, otherwise show false.
```

**Expected stdout**

```text
true
```

## #0221 · Maximal Square

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0221) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0221.html)

```text
The grid is a list of 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, and 0. The dp is a list of 20 zeros. The best is 0.
For every node from 0 to 19.
The row is node divided by 5. The column is node modulo 5.
If item node of grid is 1.
Set item node of dp to 1. If item node of dp is more than best, set best to item node of dp.
If row is more than 0 and column is more than 0.
The above is item (node minus 5) of dp. The left is item (node minus 1) of dp. The corner is item (node minus 6) of dp. The small is above. If left is less than small, set small to left. If corner is less than small, set small to corner. Set item node of dp to small plus 1. If item node of dp is more than best, set best to item node of dp.

The area is best times best. Show area.
```

**Expected stdout**

```text
4
```

## #0222 · Count Complete Tree Nodes

**Medium · Binary Search** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0222) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0222.html)

```text
Keep a shared values holding 1, 2, 3, 4, 5, and 6. Keep a shared lefts holding 1, 3, 5, -1, -1, and -1. Keep a shared rights holding 2, 4, -1, -1, -1, and -1. Keep a shared total of 0.
To gather from node (a whole number). If node is less than 0, return. Add 1 to total. Gather from item node of lefts. Gather from item node of rights.

Gather from 0. Show total.
```

**Expected stdout**

```text
6
```

## #0223 · Rectangle Area

**Medium · Math** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0223) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0223.html)

```text
The axone is -3. The ayone is 0. The axtwo is 3. The aytwo is 4. The bxone is 0. The byone is -1. The bxtwo is 9. The bytwo is 2. The awidth is axtwo minus axone. The aheight is aytwo minus ayone. The barea is awidth times aheight. The bwidth is bxtwo minus bxone. The bheight is bytwo minus byone. The bcarea is bwidth times bheight. The leftedge is axone. If bxone is more than leftedge, set leftedge to bxone. The rightedge is axtwo. If bxtwo is less than rightedge, set rightedge to bxtwo. The bottomedge is ayone. If byone is more than bottomedge, set bottomedge to byone. The topedge is aytwo. If bytwo is less than topedge, set topedge to bytwo. The overlapwidth is rightedge minus leftedge. The overlapheight is topedge minus bottomedge. The total is barea plus bcarea. If overlapwidth is more than 0 and overlapheight is more than 0, The overlaparea is overlapwidth times overlapheight, set total to total minus overlaparea.

Show total.
```

**Expected stdout**

```text
45
```

## #0224 · Basic Calculator

**Hard · String** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0224) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0224.html)

```text
The source is "(1+(4+5+2)-3)+(6+8)". Keep a shared stack as an empty list of whole numbers. Keep a shared total of 0. Keep a shared polarity of 1. Keep a shared number of 0. Keep a shared depth of 0.
To close. Increase total by polarity times number. Set number to 0. The savedpolarity is item (depth minus 1) of stack. remove the last item from stack. Decrease depth by 1. The savedtotal is item (depth minus 1) of stack. remove the last item from stack. Decrease depth by 1. Set total to savedtotal plus savedpolarity times total. Set polarity to 1.

The last is the last position of source.
For every spot from 0 to last.
The symbol is character spot of source. If symbol is between "0" and "9", The digit is the digit value of symbol, set number to number times 10 plus digit. If symbol is "+", set total to total plus polarity times number, set number to 0, set polarity to 1. If symbol is "-", set total to total plus polarity times number, set number to 0, set polarity to 0 minus 1. If symbol is "(", Place total into stack, Place polarity into stack, add 2 to depth, set total to 0, set polarity to 1. If symbol is ")", close.

Increase total by polarity times number. Show total.
```

**Expected stdout**

```text
23
```

## #0226 · Invert Binary Tree

**Easy · Depth-First Search** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0226) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0226.html)

```text
Keep a shared values holding 4, 2, 7, 1, 3, 6, and 9. Keep a shared lefts holding 1, 3, 5, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, -1, -1, -1, and -1.
To mirror from node (a whole number). If node is less than 0, return. The saved is item node of lefts. Set item node of lefts to item node of rights. Set item node of rights to saved. Mirror from item node of lefts. Mirror from item node of rights.

Mirror from 0. The queue is an empty list of whole numbers. Place 0 into queue. The head is 0. The count is 1.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. Show item node of values. The left is item node of lefts. The right is item node of rights. If left is at least 0, Place left into queue, add 1 to count. If right is at least 0, Place right into queue, add 1 to count.
```

**Expected stdout**

```text
4
7
2
9
6
3
1
```

## #0227 · Basic Calculator II

**Medium · String** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0227) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0227.html)

```text
The source is "3+2*2". Keep a shared stack as an empty list of whole numbers. Keep a shared number of 0. Keep a shared lastcode of 1. Keep a shared depth of 0. Keep a shared total of 0.
To multiply. The top is item (depth minus 1) of stack. remove the last item from stack. Decrease depth by 1. The product is top times number. Place product into stack. Add 1 to depth. Set number to 0.

To divide. The top is item (depth minus 1) of stack. remove the last item from stack. Decrease depth by 1. The quotient is top divided by number. Place quotient into stack. Add 1 to depth. Set number to 0.

To settle. If lastcode is 1, Place number into stack, add 1 to depth, set number to 0. If lastcode is 2, The neg is 0 minus number, Place neg into stack, add 1 to depth, set number to 0. If lastcode is 3, multiply. If lastcode is 4, divide.

The last is the last position of source.
For every spot from 0 to last.
The symbol is character spot of source. If symbol is between "0" and "9", The digit is the digit value of symbol, set number to number times 10 plus digit. If symbol is "+", settle, set lastcode to 1. If symbol is "-", settle, set lastcode to 2. If symbol is "*", settle, set lastcode to 3. If symbol is "/", settle, set lastcode to 4.

Settle. For each value in stack, add value to total.

Show total.
```

**Expected stdout**

```text
7
```

## #0228 · Summary Ranges

**Easy · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0228) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0228.html)

```text
Keep a shared numbers holding 0, 1, 2, 4, 5, and 7. Keep a shared last of 5. Keep a shared beginslot of 0. Keep a shared finishslot of 0. Keep a shared line as empty text. Keep a shared answers as an empty list of text.
To store. Set line to empty text. The firstlocal is beginslot. The beginvalue is item firstlocal of numbers. The begintext is format whole number beginvalue as text. Place begintext into line. The secondlocal is finishslot. The endvalue is item secondlocal of numbers. The endtext is format whole number endvalue as text. If beginslot is not finishslot, Place "->" into line, Place endtext into line. The copy is a copy of line. Place copy into answers.

For every spot from 0 to last.
The current is item spot of numbers. If spot is 0, set beginslot to spot. If spot is more than 0, The previous is item (spot minus 1) of numbers, If current is not previous plus 1, set beginslot to spot. If spot is last, set finishslot to spot, store. If spot is less than last, The next is item (spot plus 1) of numbers, If next is not current plus 1, set finishslot to spot, store.

For each answer in answers, show answer.
```

**Expected stdout**

```text
0->2
4->5
7
```

## #0229 · Majority Element II

**Medium · Array** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0229) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0229.html)

```text
Keep a shared numbers holding 3, 2, and 3. Keep a shared last of 2. Keep a shared count of 0. Keep a shared duplicate of 0.
To tally from target (a whole number). Set count to 0.
For every other from 0 to last.
If item other of numbers is item target of numbers, add 1 to count.

To check from target (a whole number). Set duplicate to 0.
For every prior from 0 to last.
If prior is less than target and item prior of numbers is item target of numbers, set duplicate to 1.

For every spot from 0 to last.
Tally from spot. Check from spot. If count times 3 is more than 3 and duplicate is 0, show item spot of numbers.
```

**Expected stdout**

```text
3
```

## #0230 · Kth Smallest Element in a BST

**Medium · Depth-First Search** · [Open in Playground](https://ponvasanthpon.github.io/TransCompilator/#problem=0230) · [Static page](https://ponvasanthpon.github.io/TransCompilator/problems/0230.html)

```text
Keep a shared values holding 3, 1, 4, and 2. Keep a shared lefts holding 1, -1, -1, and -1. Keep a shared rights holding 2, 3, -1, and -1. Keep a shared order as an empty list of whole numbers.
To gather from node (a whole number). If node is less than 0, return. Gather from item node of lefts. Place item node of values into order. Gather from item node of rights.

Gather from 0. The place is 0. Show item place of order.
```

**Expected stdout**

```text
1
```

[Chunk 05 →](chunk-05.md)
