Question Bus Routes - LeetCode
Attempts Classic DFS At first, I came oup with a classic DFS solution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 from collections import defaultdict, deque class Solution: def numBusesToDestination(self, routes: List[List[int]], source: int, target: int) -> int: adj_map = defaultdict(list) visited_map = defaultdict(lambda: False) # travers the routes to build a Adj List for r in routes: for i in range(len(r)): # reach the end if i == len(r)-1: adj_map[r[i]].
Img Source: https://unsplash.com/photos/Wpnoqo2plFA Read a CSV with PyArrow In Pandas 1.4, released in January 2022, there is a new backend for CSV reading, relying on the Arrow library’s CSV parser. It’s still marked as experimental, and it doesn’t support all the features of the default parser—but it is faster.1
CSV parser Elapsed time CPU time (user+sys) Default C 13.2 seconds 13.2 seconds PyArrow 2.7 seconds 6.5 seconds 1 2 3 import pandas as pd pd.
What is ESG ESG stands for environmental, social and governance. These are non-financial factors investors use to measure an investment or company’s sustainability. Environmental factors look at the conservation of the natural world, social factors examine how a company treats people both inside and outside the company and governance factors consider how a company is run.
ESG Investing ESG investing is a form of sustainable investing that considers environmental, social and governance factors to judge an investment’s financial returns and its overall impact.
Weekly Contest 318 This problem ate most of my time and not until a week after the contest did I realize my code wasn’t correct… So I lost 4 points which means I’ve only solved only 1 question in that weekly contest. Let’s dive right into this tricky but quite frankly easy problem.
Maximum Sum of Distinct Subarrays With Length K Maximum Sum of Distinct Subarrays With Length K Maximum Sum of Distinct Subarrays With Length K - LeetCode Contest
img source: https://unsplash.com/photos/n0CTq0rroso Heap Heap data structure is mainly used to represent a priority queue. In Python, it is available using the “heapq” module. The property of this data structure in Python is that each time the smallest heap element is popped(min-heap).
Whenever elements are pushed or popped, heap structure is maintained.
The heap[0] element also returns the smallest element each time. Let’s see various Operations on the heap in Python.