Skip to content

Instantly share code, notes, and snippets.

View feliperazeek's full-sized avatar
💭
Be there and give a shit

Felipe Oliveira feliperazeek

💭
Be there and give a shit
View GitHub Profile
### My publicly-auditable identity:
https://keybase.io/felipera
### From the command line:
Consider the [keybase command line program](https://keybase.io/download).
```bash
# look me up
@feliperazeek
feliperazeek / gist:8feb499216851612ed9de2def805aaae
Created October 27, 2016 04:07
HackerRank - Cracking the Code Interview - Sorting: Bubble Sort (https://www.hackerrank.com/challenges/ctci-bubble-sort)
import java.io.*;
import java.util.*;
public class Solution {
private static void work(int[] a) {
int swaps = 0;
int n = a.length;
@feliperazeek
feliperazeek / Solution.java
Created October 18, 2016 05:41
HackerRank - Cracking the Code Interview - Time Complexity: Primality (https://www.hackerrank.com/challenges/ctci-big-o)
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
private static boolean isPrime(int n) {
if (n <= 1) return false;
@feliperazeek
feliperazeek / Solution.java
Created October 18, 2016 05:13
HackerRank - Cracking the Code Interview - Bit Manipulation: Lonely Integer (https://www.hackerrank.com/challenges/ctci-lonely-integer)
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static int lonelyInteger(int[] a) {
int i = 0;
@feliperazeek
feliperazeek / Solution.java
Created October 15, 2016 04:41
HackerRank - Cracking the Code Interview - Queues: A Tale of Two Stacks (https://www.hackerrank.com/challenges/ctci-queue-using-two-stacks)
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
private static class MyQueue<T> {
@feliperazeek
feliperazeek / Checker.java
Created October 14, 2016 22:09
HackerRank - Cracking the Code Interview - Sorting: Comparator (https://www.hackerrank.com/challenges/ctci-comparator-sorting)
public class Checker implements Comparator<Player> {
public int compare(Player p1, Player p2) {
int score = Integer.compare(p2.score, p1.score);
if (score != 0) return score;
else return p1.name.compareTo(p2.name);
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
@feliperazeek
feliperazeek / Solution.java
Created October 14, 2016 06:13
HackerRank - Cracking the Code Interview - Stacks: Balanced Brackets (https://www.hackerrank.com/challenges/ctci-balanced-brackets)
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
private static List<Character> openChars = new ArrayList<Character>(Arrays.asList('{', '(', '['));
private static List<Character> closeChars = new ArrayList<Character>(Arrays.asList('}', ')', ']'));
@feliperazeek
feliperazeek / Solution.java
Created October 14, 2016 05:51
HackerRank - Cracking the Code Interview - Arrays: Left Rotation (https://www.hackerrank.com/challenges/ctci-array-left-rotation)
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static int[] arrayLeftRotation(int[] a, int n, int k) {
if (k < 0) throw new RuntimeException("K needs to be greater than zero");
@feliperazeek
feliperazeek / Solution.java
Created October 14, 2016 05:48
HackerRank and Cracking the Code Interview's Hash Tables: Ransom Note (https://www.hackerrank.com/challenges/ctci-ransom-note)
import java.util.*;
public class Solution {
Map<String, Integer> magazineMap;
Map<String, Integer> noteMap;
public Solution(String magazine, String note) {
magazineMap = new HashMap<String, Integer>();
noteMap = new HashMap<String, Integer>();
@feliperazeek
feliperazeek / Solution.java
Created October 14, 2016 05:37
HackerRank - Cracking Code Interview - Strings: Making Anagrams (https://www.hackerrank.com/challenges/ctci-making-anagrams)
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static int numberNeeded(String first, String second) {
Map<Character, Integer> fmap = getCharacterMap(first);