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
def StringReduction(str) | |
# code goes here | |
hash = {"ab":"c", "ac":"b", "bc":"a", | |
"ba":"c", "ca":"b", "cb":"a"} | |
count = 0 | |
while str != str[0]*str.length | |
if hash.has_key? :"#{str[count..count+1]}" | |
str = str.sub(str[count..count+1], hash[:"#{str[count..count+1]}"]) | |
count = 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
def WordSplit(strArr) | |
# code goes here | |
dict = strArr[1].split(",") | |
for i in dict | |
for j in dict | |
if i+j == strArr[0] | |
return "#{i}, #{j}" | |
end | |
end |
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
const pointlessFunction = (input: string): string => { | |
let oneToThreeObj = { | |
1: "one", 2: "two", 3: "three" | |
}; | |
let output = ""; | |
[...input].forEach((char)=>{ | |
// ts-ignore | |
if (char in oneToThreeObj) output+=oneToThreeObj[char]; | |
}); |
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
def isValid(s): | |
bracket_dic = { | |
"[":"]", | |
"{":"}", | |
"(":")" | |
} | |
open_bracket = [] | |
for i in s: | |
if i not in bracket_dic and len(open_bracket) == 0: return False |
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
let isValid = (s) => { | |
let bracket_obj = { | |
"[":"]", | |
"(":")", | |
"{":"}" | |
}; | |
let open_brackets = []; | |
for (let i = 0; i < s.length; i++) { | |
if (s[i] in bracket_obj) { | |
open_brackets.push(s[i]); |
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
# A function that takes 2 lists as arguments and returns True if the list are rotated version of each other or False otherwise. | |
def rotated(list1, list2): | |
if len(list1) != len(list2) or list1[0] == list2[0]: | |
return False | |
first_elem_list1 = list1[0] | |
if first_elem_list1 in list2: | |
index_first_elem_list2 = list2.index(first_elem_list1) | |
else: return False |
OlderNewer