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
fun solution(a: IntArray): Int { | |
val nrSplits = a.size - 1 | |
val differences = IntArray(nrSplits) | |
var leftTape = 0 | |
var rightTape = a.sum() | |
var x: Int | |
for (p in 1..nrSplits) { | |
x = a[p-1] |
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
fun solution(a: IntArray): Int { | |
// First edge case: missing is the first nr | |
if (a.isEmpty()) return 1 | |
a.sort() | |
for (i in a.indices) { | |
// Index 0 must be 1, Index 1 must be 2, and so on. | |
// Whenever that's not true, we found our missing nr | |
if (a[i] != i + 1) return i + 1 |
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
fun solution(x: Int, y: Int, d: Int): Int { | |
val distance = y - x | |
val jumps = distance / d | |
// If the jumps are 1.1, that means 2 jumps. | |
return if (distance % d == 0) jumps else jumps + 1 | |
} |
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
fun solution(A: IntArray): Int { | |
var unpairedElement = 0 | |
for (element in A) unpairedElement = unpairedElement xor element | |
return unpairedElement | |
} |
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
fun solution(A: IntArray): Int { | |
val counter = HashSet<Int>() | |
for (i in A) if (!counter.remove(i)) counter.add(i) | |
return counter.first() | |
} |
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
fun solution(n: Int): Int { | |
var longestBinaryGap = 0 | |
var currentBinaryGap = 0 | |
var isCounting = false | |
// Get binary representation | |
val binaryString = Integer.toBinaryString(n) | |
for (char in binaryString) { | |
when { |
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.*; | |
import java.util.concurrent.*; | |
class Main { | |
public static void main(String[] args) { | |
Set<Integer> s = Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>()); | |
CopyOnWriteArrayList<Integer> a = new CopyOnWriteArrayList<>(); | |
int total1 = 0; | |
int total2 = 0; |
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
/* | |
# Exploit Title: ofs.c - overlayfs local root in ubuntu | |
# Date: 2015-06-15 | |
# Exploit Author: rebel | |
# Version: Ubuntu 12.04, 14.04, 14.10, 15.04 (Kernels before 2015-06-15) | |
# Tested on: Ubuntu 12.04, 14.04, 14.10, 15.04 | |
# CVE : CVE-2015-1328 (http://people.canonical.com/~ubuntu-security/cve/2015/CVE-2015-1328.html) | |
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* | |
CVE-2015-1328 / ofs.c |