Write an algorithm to find the next largest number by rearranging digits.
Given a non-negative integer n, return the smallest integer greater than n that uses exactly the same digits. Return -1 if no greater rearrangement exists. Implement next_largest_number(n), where the input and output are integers.
def next_largest_number(n):