This file contains 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
import os | |
import datetime | |
import google.auth | |
from google.oauth2.credentials import Credentials | |
from googleapiclient.discovery import build | |
SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"] | |
CREDENTIALS_FILE = "credentials.json" | |
LUMA_CALENDAR_ID = "[email protected]" |
This file contains 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
public boolean[][] allSubstrings(String S) { | |
int N = S.length(); | |
int count=0; | |
boolean [][] dp = new boolean [N][N]; | |
for(int i=0;i<N;i++){ | |
dp[i][i] = true; | |
count++; | |
if(i+1<N && S.charAt(i)==S.charAt(i+1)) { | |
dp[i][i+1] = true; |
This file contains 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
["StockPrice","update","maximum","current","minimum","maximum","maximum","maximum","minimum","minimum","maximum","update","maximum","minimum","update","maximum","minimum","current","maximum","update","minimum","maximum","update","maximum","maximum","current","update","current","minimum","update","update","minimum","minimum","update","current","update","maximum","update","minimum"] | |
[[],[38,2308],[],[],[],[],[],[],[],[],[],[47,7876],[],[],[58,1866],[],[],[],[],[43,121],[],[],[40,5339],[],[],[],[32,5339],[],[],[43,6414],[49,9369],[],[],[36,3192],[],[48,1006],[],[53,8013],[]] | |
output | |
[null,null,2308,2308,2308,2308,2308,2308,2308,2308,2308,null,7876,2308,null,7876,1866,1866,7876,null,121,7876,null,7876,7876,5339,null,5339,121,null,null,1866,1866,null,3192,null,9369,null,1006] | |
expected | |
[null,null,2308,2308,2308,2308,2308,2308,2308,2308,2308,null,7876,2308,null,7876,1866,1866,7876,null,121,7876,null,7876,7876,1866,null,1866,121,null,null,1866,1866,null,1866,null,9369,null,1006] |
This file contains 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 StockPrice { | |
TreeMap<Integer,Integer> timeToPrice; | |
TreeMap<Integer,Integer> priceToTime; | |
int current; | |
public StockPrice() { | |
timeToPrice = new TreeMap<>(); | |
priceToTime = new TreeMap<>(); | |
current =0; |
This file contains 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 Item { | |
long cost; | |
int ticketsUsed; | |
long discount; | |
public Item(long cost, int ticketsUsed, long discount) { | |
this.cost = cost; | |
this.ticketsUsed = ticketsUsed; | |
this.discount = discount; | |
} | |
} |
This file contains 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
public int minValue(int N) { | |
if(N==0) return 1; | |
if((N&N-1)==0) return 1; | |
int x = Integer.bitCount(N); | |
int count=0; // is the number of bit set in N | |
int t = N; | |
while(t>0){ | |
t>>=1; |
This file contains 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
long countOfNumbers(long N, int[]primeArray) { | |
long sum=0; | |
int totalNumberOfSubsets = 1<<primeArray.length; | |
// loop to generate all subsets from prime array | |
for(int i=1;i<totalNumberOfSubsets;i++) { | |
long count=1; |
This file contains 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
private int findIndex(String S){ | |
int N = S.length(); | |
int ans = (1<<N)-2; | |
int pos=0,i=N-1; | |
while(i>=0) { | |
if(S.charAt(i)=='7') { | |
ans += (1<<pos); | |
} | |
i--; | |
pos++; |
This file contains 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
public void takeExam(int N) throws Exception { | |
TestData[] array = new TestData[N]; | |
for(int i=0;i<N;i++) { | |
array[i] = new TestData(input.nextInt(), input.nextInt()); | |
} | |
Arrays.sort(array, (x,y) -> { | |
return (x.actual!=y.actual) ? (x.actual-y.actual) : (x.allowed-y.allowed); |
This file contains 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
public void findMax(int N) throws Exception { | |
final int maxN = 100007; | |
long [] freqMap = new long[maxN]; | |
for(int i=1;i<=N;i++){ | |
freqMap[getNextInt()]++; | |
} | |
long [] dp = new long[maxN]; | |
dp[0] = 0; | |
dp[1] = freqMap[1]; |
NewerOlder