Created
November 21, 2024 16:19
-
-
Save prio101/456878dd61c506ac58d10c595de6d926 to your computer and use it in GitHub Desktop.
test_for_airwork.ai.rb
This file contains hidden or 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
# Anagram Problem | |
def is_anagram(string_one, string_two) | |
return false if string_one.length != string_two | |
return true if string_one.sort == string_two | |
false | |
end | |
is_anagram("car", "rat") # should return false | |
is_anagram("anagram", "naagram") # should return true | |
# two sum | |
# two sum | |
# | |
arr = [2, 7, 11, 15] | |
target = 9 | |
def get_two_sum(arr, target) | |
uniq_arr = arr.uniq | |
uniq_arr.each do |value, index| | |
uniq_arr[index..uniq_arr.length].each |value_two, jindex| | |
return [index, jindex] if ( value + value_two ) == target.to_i | |
end | |
end | |
end | |
get_two_sum(arr, target) # this should return the value [0, 1] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment