I am trying to implement the searchsorted algorithm(side=right) in scala that is, find last index where an element should be inserted in order to maintain the sorting order.