-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruby_intro_TeamName_achetwa_unityID2.rb
More file actions
62 lines (56 loc) · 1.44 KB
/
Copy pathruby_intro_TeamName_achetwa_unityID2.rb
File metadata and controls
62 lines (56 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Part 1
def two_sum?(a, n)
# ADD YOUR CODE HERE
end
def max_sub_array(a)
# ADD YOUR CODE HERE
end
def group_anagrams(a)
# ADD YOUR CODE HERE
end
# Part 2
def brackets_match?(s)
st_br=[] #declare array which can be used as stack
s.each_char do |x| #iterate through each bracket
y = st_br[-1] # get the bracket at the top of the stack
if y == ']' || y == ')' || y == '}' # closing for no opening
return false
end
if x == ']' && y == '[' ||
x == ')' && y == '(' ||
x == '}' && y == '{' ||
st_br.pop
else
st_br.push(x)
end
end
return st_br.empty?
end
def remove_and_append_vowels(s)
vow = []
not_vow = []
s.scan(/[AEIOUaeiou]/) do |x| #check if vowels
vow.push(x)
end
s.scan(/[^AEIOUaeiou]/) do |x| #check if not a vowel
not_vow.push(x)
end
vow_string = vow.join
not_vow_string = not_vow.join
ans = not_vow_string + vow_string
return ans
# ADD YOUR CODE HERE
end
def highest_frequency_word(s)
test_string_array = test_string.split(" ") #split into array
freq_map = Hash.new{0} #create map with deafult freq as 0
test_string_array.each do |word| #iterate the array
freq_map[word] +=1 #calculate teh frequnce
end
ans= freq_map.key(freq_map.values.max) #gives the frequency of the most recent word with max occurances
return ans
end
# Part 3
class Book
# ADD YOUR CODE HERE
end