Skip to content

Instantly share code, notes, and snippets.

View remi-bruguier's full-sized avatar
🎯

Rémi BRUGUIER remi-bruguier

🎯
View GitHub Profile
@remi-bruguier
remi-bruguier / buyAndSell.ts
Created June 13, 2020 20:43
You are given an array. Each element represents the price of a stock on that particular day. Calculate and return the maximum profit you can make from buying and selling that stock only once.
const buy_and_sell = (values:number[]):number => {
let maxProfit = 0;
let minPrice = Number.MAX_SAFE_INTEGER;
for(let val of values){
if(val<minPrice) {
minPrice = val;
}else if(val - minPrice > maxProfit){
maxProfit = val - minPrice;
}
}
@remi-bruguier
remi-bruguier / kalAsh.ts
Created July 6, 2020 19:29
Trouvez une chaîne de 9 caractères (seulement constituées des lettres "acdegilmnoprstuw") telle que hash(la_string) soit 956446786872726 si le hash est défini par le code suivant :
/* Int64 hash (String s) {
Int64 h = 7
String letters = "acdegilmnoprstuw"
for(Int32 i = 0; i < s.length; i++) {
h = (h * 37 + letters.indexOf(s[i]))
}
return h
} */
/**
* Given a string, we want to remove 2 adjacent characters that are the same, and repeat the process with the new string until we can no longer perform the operation.
*
* @param base the original string
*
* @returns the `cleansed` string
*/
const remove_adjacent_dup = (base:string): string => {
const adjacentDupRegex = new RegExp(/(\w)\1/g);
while(adjacentDupRegex.test(base)){