This file contains 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) |
This file contains 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 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 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 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 FizzBuzz { | |
static void main(String[] args) { | |
(1..100).each {println((it % 3 ? '' : 'fizz') + (it % 5 ? '' : 'buzz') ?: it)} | |
} | |
} |
This file contains 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
import java.util.regex.Matcher | |
class Palindrome { | |
static void main(String[] args) { | |
def stuff = 'This, stuff ala ffuts, is a sentence to isPalindrome (tacocat)!!ONE!1!' | |
findPalindromes(stuff, true, true) | |
println '==================' | |
findPalindromes(stuff, true, true, true) | |
println '==================' | |
findPalindromes(stuff, false, true) |
This file contains 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 ReverseArray { | |
/* | |
Input: str = "a,b$c" | |
Output: str = "c,b$a" | |
Note that $ and , are not moved anywhere. | |
Only subsequence "abc" is reversed | |
Input: str = "Ab,c,de!$" | |
Output: str = "ed,c,bA!$" | |
*/ |
This file contains 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 ReverseNumberArray { | |
static void main(String[] args) { | |
int[] arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
println "original: $arr" | |
println "reversed: ${reverse(arr, 0, arr.size() - 1)}" | |
} | |
static int[] reverse(int[] arr, int left, int right) { | |
int temp = arr[right] | |
arr[right] = arr[left] |
This file contains 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
import java.util.*; | |
class RpnCalculator { | |
static void main(String[] args) { | |
Calculator calc = new Calculator() | |
'4 6 3 + 9 3 - * 1 1 ^ - +'.split(' ').each {calc.enter(it)} | |
} | |
} | |
class Calculator { |
This file contains 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
#!/bin/bash | |
# put this in root/docker_start_master.sh | |
# Make files owned by jenkins (not root). This didn't work when done from the Dockerfile build. | |
chown -R jenkins:jenkins /var/jenkins_home | |
# Need to make sure docker.sock is in the "docker" group so that the "jenkins" user can use it: | |
chown root:docker /var/run/docker.sock | |
# Work-around a problem we're having with the container (running as a UCP service) not having DNS set-up: |
NewerOlder