Skip to content

Instantly share code, notes, and snippets.

View sidsbrmnn's full-sized avatar
🎯
Focusing

Siddharth Subramanian sidsbrmnn

🎯
Focusing
View GitHub Profile
@sidsbrmnn
sidsbrmnn / SafeCoroutine.cs
Created July 21, 2025 21:38
Unity Safe Coroutines
using System;
using System.Collections;
using UnityEngine;
public class SafeCoroutine
{
private Coroutine _coroutine;
private IEnumerator _routine;
private MonoBehaviour _owner;
@sidsbrmnn
sidsbrmnn / min_distance.cc
Last active July 8, 2025 07:59
7-Eleven SDE 2 Interview
/**
* Problem Statement:
* -------------------
* Given an array of integers and two distinct integers x and y,
* the task is to find the minimum distance between any occurrence of x and y in the array.
* The distance between two positions is defined as the absolute difference of their indexes.
*
* Example:
* ---------
* Input:
/*
Problem Statement:
Given two strings s and t, count the number of subsequences of s (including the
empty subsequence) such that the lexicographical order of the subsequence is
strictly greater than string t.
- You can choose any subsequence of s by deleting zero or more characters.
- For comparison, if the chosen subsequence is shorter than t, pad it with
characters to compare as necessary.
- Return the count modulo 1e9 + 7.
@sidsbrmnn
sidsbrmnn / luhn.py
Created April 1, 2025 23:32
Luhn's algorithm for validating credit card numbers / IMEI
def luhn(s: str) -> bool:
sum = 0
for i in range(len(s) - 1, -1, -2):
sum += int(s[i])
if i != 0:
dd = int(s[i-1]) * 2
if dd > 9:
dd -= 9
sum += dd
@sidsbrmnn
sidsbrmnn / min_total_risk_cost.cc
Created March 19, 2025 06:41
TikTok 15-19 Mar Assessment
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
int min_total_risk_cost(vector<int> &scores, int k) {
int n = scores.size();
@sidsbrmnn
sidsbrmnn / SpawnerAuthoring.cs
Last active November 6, 2024 18:55
Usage of Additional Entities in Unity DOTS
using System;
using Unity.Entities;
using UnityEngine;
public struct Spawner : IComponentData
{
public Entity Prefab;
public float Interval;
}
@sidsbrmnn
sidsbrmnn / go_fish.cpp
Created October 3, 2024 06:48
Go Fish Boilerplate for CS 396
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <vector>
using namespace std;
@sidsbrmnn
sidsbrmnn / depsort.py
Created January 10, 2024 00:24
Dependency graph sorter
from collections import defaultdict
from itertools import chain
class Graph:
def __init__(self, vertices: list[str]):
self._graph = defaultdict(list)
self._V = vertices
def add_edge(self, u: str, v: str):
@sidsbrmnn
sidsbrmnn / sieve_of_eratosthenes.c
Last active September 29, 2024 00:46
C implementation of the Sieve of Eratosthenes to finding all prime numbers up to any given limit.
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int *sieve_of_eratosthenes(const int n) {
int *primes = (int *)malloc(sizeof(int) * (n + 1));
for (int i = 0; i < n + 1; i++) {
primes[i] = 1;
}
@sidsbrmnn
sidsbrmnn / hashtable.c
Last active April 18, 2020 13:01
Hash table in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TABLE_SIZE 10000
typedef struct entry_t {
char *key;
char *value;
struct entry_t *next;