This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
algorithm: | |
1. Find shortest path between start and goal nodes | |
and multiply distance with 6. | |
2. If distance does not exist in graph that means | |
replace it with -1 because it is not connected to start node | |
''' | |
from collections import defaultdict |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mergeIntervals(arr): | |
sorted(arr) | |
index=0 | |
for i in range(len(arr)): | |
if(index!=0 and arr[index-1][0]<=arr[i][1]): | |
while(index!=0 and arr[index-1][0]<arr[i][1]): | |
arr[index-1][1]=max(arr[index-1][1], arr[i][1]) | |
arr[index-1][0]=min(arr[index-1][0], arr[i][0]) | |
index-=1 | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
countStaircase={} | |
def countSteps(n): | |
if n in countStaircase: | |
return countStaircase[n] | |
elif n==0: | |
return 1 | |
elif n<0: | |
return 0 | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, data): | |
self.data=data | |
self.nex=None | |
def prkte(cur, k): | |
if(cur.nex==None): | |
if(k-1==0): | |
print(cur.data) | |
return k-1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
class Graph: | |
def __init__(self): | |
self.graph=defaultdict(list) | |
self.V=len(self.graph) | |
def addEdge(self, u, v): | |
self.graph[u].append(v) | |
self.V=len(self.graph) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <assert.h> | |
using namespace std; | |
struct result{ | |
double maxiSelPrice; | |
double miniSelPrice; | |
double comRangeL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, data): | |
self.data=data | |
self.nex=None | |
def revList(head): | |
trail=head | |
cur=head.nex | |
temp=cur.nex | |
trail.nex=None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def maxFish(grid): | |
nc=grid[0] | |
for i in range(len(nc)): | |
if(i!=0): | |
nc[i]+=grid[0][i-1] | |
for i in range(1,len(grid)): | |
for j in range(len(grid[0])): | |
if (j!=0): | |
nc[j]=max(grid[i][j]+nc[j], nc[j-1]+grid[i][j]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def numWays(n, m): | |
num=[1]*min(n, m) | |
for i in range(max(n,m)-1): | |
for j in range(min(n,m)): | |
if j!=0: | |
num[j]+=num[j-1] | |
return(num[n-1]) | |
print(numWays(2,5)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recRev(x, y): | |
if(x>0): | |
y+=x%10 | |
return (recRev(x/10, y*10)) | |
else: | |
return (y/10) |
NewerOlder