Skip to content

Instantly share code, notes, and snippets.

View iafsilva's full-sized avatar

Ivo Silva iafsilva

View GitHub Profile
@iafsilva
iafsilva / TapeEquilibrium.kt
Created May 26, 2023 14:44
TapeEquilibrium
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]
@iafsilva
iafsilva / MissingPermElem.kt
Created May 19, 2023 15:00
MissingPermElem
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
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
}
@iafsilva
iafsilva / OddOccurrencesInArray_ultimate.kt
Last active May 4, 2023 15:11
OddOccurrencesInArray-UltimateSolution
fun solution(A: IntArray): Int {
var unpairedElement = 0
for (element in A) unpairedElement = unpairedElement xor element
return unpairedElement
}
@iafsilva
iafsilva / OddOccurrencesInArray_weak.kt
Created May 4, 2023 15:04
OddOccurrencesInArray-MidSolution
fun solution(A: IntArray): Int {
val counter = HashSet<Int>()
for (i in A) if (!counter.remove(i)) counter.add(i)
return counter.first()
}
@iafsilva
iafsilva / BinaryGap.kt
Last active April 27, 2023 18:52
BinaryGap Solution
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 {
@iafsilva
iafsilva / list_set_test.java
Created December 18, 2018 16:17
Benchmark for testing addition and iteration of elements into a list vs a set
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;
/*
# 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