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 |
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
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
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 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
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
# We define to be a permutation of the first natural numbers in the range . Let denote the value at position in permutation using -based indexing. | |
# is considered to be an absolute permutation if holds true for every . | |
# Given and , print the lexicographically smallest absolute permutation . If no absolute permutation exists, print -1. | |
# Example | |
# Create an array of elements from to , . Using based indexing, create a permutation where every . It can be rearranged to so that all of the absolute differences equal : |
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 modified Kaprekar number is a positive whole number with a special property. If you square it, then split the number into two integers and sum those integers, you have the same value you started with. | |
# Consider a positive whole number with digits. We square to arrive at a number that is either digits long or digits long. Split the string representation of the square into two parts, and . The right hand part, must be digits long. The left is the remaining substring. Convert those two substrings back to integers, add them and see if you get . | |
# Example | |
# First calculate that . Split that into two strings and convert them back to integers and . Test , so this is not a modified Kaprekar number. If , still , and . This gives us , the original . |
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
# you're given a list of time intervals during which students at a school need a laptop. | |
# These time intervals are represented by pairs of integers [start, end], where 0 <= start < end. | |
# However, start and end don't represent real times; therefore, they may be greater than 24. | |
# No two students can use a laptop at the same time, but immediately after a student is done | |
# using a laptop, another student can use that same laptop. For example, if one student rents a | |
# laptop during the time interval [0, 2], another student can rent the same laptop during any | |
# time interval starting with 2. Write a function that returns the minimum number of laptops | |
# that the school needs to rent such that all students will always have access to a laptop when | |
# they need one. laptopRentals(times) | |
# Parameters times: Array (of Array (of Integers)) - A 2D array containing the times the |
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
# Given a sequence of integers , a triplet is beautiful if: | |
# Given an increasing sequenc of integers and the value of , count the number of beautiful triplets in the sequence. | |
# Example | |
# There are three beautiful triplets, by index: . To test the first triplet, and . | |
# Function Description |
NewerOlder