You are viewing a single comment's thread. Return to all comments →
I'm working with Ruby... when I'm using Visual Studio, the code seems to work, however it doesn't work on HackerRank.. please help!
def quadrants(p, queries) # Write your code here queries.each do |query| if query[0] == "X" ((query[1].toi-1)...query[2].toi).each do |i| p[i][1] = -1 end elsif query[0] == "Y" ((query[1].toi-1)...query[2].toi).each do |i| p[i][0] = -1 end else count1 = 0 count2 = 0 count3 = 0 count4 = 0 ((query[1].toi-1)...query[2].toi).each do |i| if p[i][0] > 0 && p[i][1] > 0 count1 += 1 elsif p[i][0] < 0 && p[i][1] > 0 count2 += 1 elsif p[i][0] < 0 && p[i][1] < 0 count3 += 1 elsif p[i][0] > 0 && p[i][1] < 0 count4 += 1 end end print [count1,count2,count3,count4].join(" ") puts end end end
Seems like cookies are disabled on this browser, please enable them to open this website
Quadrant Queries
You are viewing a single comment's thread. Return to all comments →
I'm working with Ruby... when I'm using Visual Studio, the code seems to work, however it doesn't work on HackerRank.. please help!
def quadrants(p, queries) # Write your code here queries.each do |query| if query[0] == "X" ((query[1].toi-1)...query[2].toi).each do |i| p[i][1] = -1 end elsif query[0] == "Y" ((query[1].toi-1)...query[2].toi).each do |i| p[i][0] = -1 end else count1 = 0 count2 = 0 count3 = 0 count4 = 0 ((query[1].toi-1)...query[2].toi).each do |i| if p[i][0] > 0 && p[i][1] > 0 count1 += 1 elsif p[i][0] < 0 && p[i][1] > 0 count2 += 1 elsif p[i][0] < 0 && p[i][1] < 0 count3 += 1 elsif p[i][0] > 0 && p[i][1] < 0 count4 += 1 end end print [count1,count2,count3,count4].join(" ") puts end end end