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
class CountTriplets { | |
static void main(String[] args) { | |
// (-2, 0, 1) and (-2, 0, 3) == 2 | |
println "count=${count([-2, 0, 1, 3] as int[], 2)}" | |
// (1, 3, 4), (1, 3, 5), (1, 3, 7), (1, 4, 5) == 4 | |
println "count=${count([5, 1, 3, 4, 7] as int[], 12)}" | |
// (2, 3, 4), (2, 3, 5), (2, 3, 8), (2, 4, 5), (3, 4, 5) == 5 | |
println "count=${count([9, 5, 3, 2, 4, 8] as int[], 14)}" |
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
class SortedArrays { | |
/* | |
For Example | |
A = {10, 15, 25} | |
B = {1, 5, 20, 30} | |
The resulting arrays are: | |
10 20 | |
10 20 25 30 | |
10 30 |
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
class ZigZag { | |
/* | |
Example: | |
Input: arr[] = {4, 3, 7, 8, 6, 2, 1} | |
Output: arr[] = {3, 7, 4, 8, 2, 6, 1} | |
Input: arr[] = {1, 4, 3, 2} | |
Output: arr[] = {1, 4, 2, 3} | |
*/ | |
static void main(String[] args) { |
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
class BinaryTreeBottomView { | |
public static void main(String[] args) { | |
Node root = new Node(20) | |
root.left = new Node(8) | |
root.right = new Node(22) | |
root.left.left = new Node(5) | |
root.left.right = new Node(3) | |
root.right.left = new Node(4) | |
root.right.right = new Node(25) | |
root.left.right.left = new Node(10) |
OlderNewer