Skip to content

Instantly share code, notes, and snippets.

View kushaagr's full-sized avatar
🏹
Aiming high

Kushagra Mehrotra kushaagr

🏹
Aiming high
  • Bangalore, India
  • 16:57 (UTC +05:30)
  • LinkedIn in/kushaagr
View GitHub Profile
@kushaagr
kushaagr / chdir-to-current-file.py
Last active March 23, 2025 16:14
[Change PWD to main] Set pwd in python environment to current file's location
# Get the absolute path of the directory containing main.py
script_dir = os.path.dirname(os.path.abspath(__file__))
# Change the current working directory to script_dir
os.chdir(script_dir)
print("Current Working Directory:", os.getcwd())
@kushaagr
kushaagr / connected-components.py
Last active March 23, 2025 16:13
[Connected components] Count connected components using DFS
def recursivelyMark(nodeID, nodes):
(connections, visited) = nodes[nodeID]
if visited:
return
nodes[nodeID][1] = True
for connectedNodeID in connections:
recursivelyMark(connectedNodeID, nodes)
def main():
nodes = [[[1], False], [[0], False], [[3], False], [[2], False], [[], False], [[], False]]