This file contains hidden or 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
| def nearest_larger1(arr, idx) | |
| diff = 1 | |
| loop do | |
| left = idx - diff | |
| right = idx + diff | |
| return nil if left < 0 && right >= arr.length | |
| if (left >= 0) && (arr[left] > arr[idx]) | |
| return left |
This file contains hidden or 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
| def rec_intersection(rec_a, rec_b) | |
| #if rec_a is contained within rec_b, return rec_a | |
| if rec_a[0][0] > rec_b[0][0] && rec_a[0][1] > rec_b[0][1] | |
| if rec_a[1][0] < rec_b[1][0] && rec_a[1][1] < rec_b[1][1] | |
| return rec_a | |
| end | |
| end | |
| #if rec_b is contained within rec_a, return rec_b |