public int[] sortTransformedArray(int[] nums, int a, int b, int c) {
        if (nums == null) return null;

        int n = nums.length;
        int[] res = new int[n];

        int i = 0, j = n - 1;
        int p = a > 0 ? n - 1 : 0;
        while (i <= j) {
            if (a > 0) {
                res[p--] = f(nums[j], a, b, c) > f(nums[i], a, b, c) ? f(nums[j--], a, b, c) : f(nums[i++], a, b, c);
            } else {
                res[p++] = f(nums[j], a, b, c) > f(nums[i], a, b, c) ? f(nums[i++], a, b, c) : f(nums[j--], a, b, c);
            }
        }
        return res;
    }