Skip to content

Instantly share code, notes, and snippets.

🌴
On vacation

t k tahia-khan

🌴
On vacation
Block or report user

Report or block tahia-khan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View PermMissingElem.py
# you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"
def solution(A):
# write your code in Python 2.7
L = len(A)
if not L: return 0
sum = 0
View TapeEquilibrium.py
# you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"
def solution(A):
# write your code in Python 2.7
L = len(A)
min = 1000
if L == 1:
View oddoccurances.py
# you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"
def solutionA(A): # 100% but space complexity is not O(1)
L = len(A)
d = {}
if not L: return
for e in A:
View qsort.py
def qsort(A, L, U):
if L < U:
P = A[L]
W = L
for i in range(L, U):
if A[i] < P:
W += 1
tmp = A[i]
A[i] = A[W]
A[W] = tmp
View CyclicRotation.py
# you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"
def solution(A, K):
# write your code in Python 2.7
result = []
L = len(A)
if L <= 1 or not K or L == K:
return A
View io_error.c
#include <stdio.h>
#include <stdlib.h>
int main() {
int nbytes, ncases, i, j, k;
char c, res;
char ** msgs;
scanf("%d", &ncases);
msgs = malloc(ncases * sizeof(char *));
@tahia-khan
tahia-khan / quickest_route.c
Created Nov 10, 2015
given a time-table, a starting city, a starting time and a destination city, how would you compute the soonest you could get to the destination city?
View quickest_route.c
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define N_CITIES 4
typedef enum{A, B, C, D, None=-1}city;
typedef struct {
int start;
@tahia-khan
tahia-khan / maze.c
Created Nov 10, 2015
given a 2d array of black and white entries representing a maze with designated entrance and exit points, find a path from the entrance to the exist, if one exists.
View maze.c
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define N 5
typedef enum{BLACK, WHITE, START, END} tile;
typedef enum{UNDISCOVERED, DISCOVERED, PROCESSED}graph_state;
typedef struct {
@tahia-khan
tahia-khan / qsort_3parts.c
Created Nov 10, 2015
qsort with 3 way partitions (<T, ==T, >T)
View qsort_3parts.c
#include <stdio.h>
void qsort3(int *X, int L, int U) {
int T, M, E, i, tmp;
if (L < U) {
T = X[L];
M = L;
E = U;
for (i = L+1; i < E; i++) {
if (X[i] < T) {
@tahia-khan
tahia-khan / detect_cycles.py
Last active Nov 9, 2015
given adjacency matrix, detect # of cycles in directed graph
View detect_cycles.py
def find_cycles(g, x, path, num_cycles):
if x in path:
num_cycles+=1
return num_cycles
path.append(x)
N = len(g[x])
for i in range(N):
if g[x][i]:
You can’t perform that action at this time.