working for some test cases, not all
working brute force