Skip to content

lugolabs/pivot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

pivot

Write a method that returns the "pivot" index of a list of integers. We define the pivot index as the index where the sum of the numbers on the left is equal to the sum of the numbers on the right. Given [1, 4, 6, 3, 2], the method should return 2, since the sum of the numbers to the left of index 2 is equal to the sum of numbers to the right of index 2 (1 + 4 = 3 + 2). If no such index exists, it should return -1. If there are multiple pivots, you can return the left-most pivot.

You can write the method in any language. Make sure that the method:

  • runs successfully
  • handles all edge cases
  • is as efficient as you can make it!

A successful answer will fulfill the above criteria.

Solution

Run the solution to a terminal. First cd to the pivot folder then run:

ruby pivot.rb

All tests should pass.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages