How can I write an algorithm to check if the sum of any two numbers in an array/list matches a given number with a complexity of nlogn
?
While traversing each elements of array, add element of both the array and carry from the previous sum. Now store the unit digit of the sum and forward carry for the next index sum. While adding 0th index element if the carry left, then append it to beginning of the number.
Step 1: Start. Step 2: Read A, B. Step 3: Sum=A+B. Step 4: Print Sum.
The Arrays. equals() method checks the equality of the two arrays in terms of size, data, and order of elements. This method will accept the two arrays which need to be compared, and it returns the boolean result true if both the arrays are equal and false if the arrays are not equal.
I'm sure there's a better way, but here's an idea:
Both these operations are O(n log n)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With