Skip to content

Instantly share code, notes, and snippets.

View rohit-jamuar's full-sized avatar

Rohit rohit-jamuar

  • Intel
  • Austin, TX
View GitHub Profile
@rohit-jamuar
rohit-jamuar / gray_code_gen.py
Last active March 31, 2018 19:33
Generate n-bit gray codes
#!/usr/bin/env python3
'''
python3 gray_code_gen.py 5
'''
def gray_code(n):
#Generate n-bit gray-codes (starting from 0000..(n times))
def __gray_codes_rec1():
if len(CODE_SEQ) == MAX_SEQ_LEN:
return CODE_SEQ
current = CODE_SEQ[-1]
@rohit-jamuar
rohit-jamuar / The Technical Interview Cheat Sheet.md
Created December 13, 2017 17:59 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@rohit-jamuar
rohit-jamuar / Dockerfile
Created October 16, 2017 20:47 — forked from alkrauss48/Dockerfile
Running a docker container as a non-root user
# By default, Docker containers run as the root user. This is bad because:
# 1) You're more likely to modify up settings that you shouldn't be
# 2) If an attacker gets access to your container - well, that's bad if they're root.
# Here's how you can run change a Docker container to run as a non-root user
## CREATE APP USER ##
# Create the home directory for the new app user.
RUN mkdir -p /home/app
@rohit-jamuar
rohit-jamuar / find_longest.py
Created April 15, 2015 21:46
Longest word (from a list of words) which can be found in the input grid while making a KNIGHT's stride
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Find longest word (from a list of words) which can be found in the
input grid while making a KNIGHT's stride.
'''
from collections import defaultdict
@rohit-jamuar
rohit-jamuar / file_indexer.py
Last active August 29, 2015 14:19
MapReduce (top k words) using multiproc
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Simple Distributed File Indexer v0.1 : 'MapReduce with multiproc'
'''
from multiprocessing import Pool
from collections import defaultdict
from re import findall, compile
@rohit-jamuar
rohit-jamuar / radix_sort.py
Created April 8, 2015 20:16
O(kn) integer sorting
def max_num_len(arr):
x = max(arr)
count = 0
while x > 0:
x /= 10
count += 1
return count
def radix_sort(arr):
@rohit-jamuar
rohit-jamuar / combine_permute.py
Created March 30, 2015 21:42
Find all combinations / permutations of a string
def combine(s):
if len(s) <= 1:
return {'', s}
last_char = s[-1]
result = combine(s[:-1])
intermediate = {i for i in result}
for item in result:
intermediate.add(item + last_char)
return list(intermediate)
@rohit-jamuar
rohit-jamuar / binary_tree.py
Last active August 29, 2015 14:18
Binary Tree with a print generator
class BiNode(object):
'''
A binary tree node
'''
def __init__(self, val):
self.value = val
self.left, self.right = None, None
@rohit-jamuar
rohit-jamuar / generate_alpha_combinations.py
Last active August 29, 2015 14:16
Generates all combinations of case-alternating alphabets from string argument
def generate_combinations(s):
'''
Generates all combinations of case-alternating alphabets from string 's'
for e.g. if 's' was '0abc', the function would output:
0abc
0abC
0aBc
0aBC
0Abc
0AbC
@rohit-jamuar
rohit-jamuar / get_subsequences.py
Last active August 29, 2015 14:05
Yields all subsequences of input string
#!/usr/bin/python
from itertools import combinations
def get_subsequences(input_str):
'''
Yields all subsequences of size in range [1, len(input_str)]
'''
if type(input_str) == str:
for length in range(1, len(input_str)+1):