Skip to content

Commit e1bd790

Browse files
authored
Merge pull request #3 from Shoaib19/Shoaib019
2 more ruby questions
2 parents 9539862 + 228d930 commit e1bd790

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Ruby/count_consective_numbers.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Name: Shoaib Sabir
2+
# Username: Shoaib019
3+
# Approach: make hash count as value and number as key then find max value return its key
4+
def count_consective_numbers(arr)
5+
hash_one = {}
6+
arr.each do |val|
7+
hash_one[val] = arr.count(val)
8+
end
9+
hash_one.max_by {|k,v| v}.first
10+
end

Ruby/jump_tiles.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Name: Shoaib Sabir
2+
# Username: Shoaib019
3+
# Approach: in loop added only those elements on which pointer value is same
4+
# then compare pointer value with size of array
5+
def jump_tiles(arr)
6+
pointer = 0
7+
arr.each_with_index do |_,idx|
8+
pointer = pointer + arr[idx] if pointer == idx
9+
end
10+
pointer >= arr.length - 1 ? true : false
11+
end

0 commit comments

Comments
 (0)