12 Replies
lets use the first data test case
1 is listed twice so it returns true
but my second loop tests for i+1. so j= i +1 right
lets assume i is at number 3 in the first test case. then j (which is i+1) would be at 1
3 and 1 are not the same so why does it return true?
Did you use the debugger?
It will let you see what each value is at any given point
the other solutions are like this to
im just confused on how its correct
if i said j = i+3 then that would make sense
because if i is at 1. then j would be at 1 again
but i said j = i+1
so i and j should never be the same number
yet it still works
i=0
=> j=1,2,3
i=1
=> j=2,3
i=2
=> j=3
i=3
=> j=
It never compares numbers on the same positionwait what
so j
numbers[x]
will never be compared with numbers[x]
is all the numbers past i?
not just the number infront of i
Well, yes, you start with a
j
that is one higher than i
if i have an array {1,2,3,4,5}
and i is at number 2.
then j would be number 3 no?
assuming j is i+1?
Angius
REPL Result: Success
Console Output
Compile: 494.046ms | Execution: 70.268ms | React with ❌ to remove this embed.
Angius
REPL Result: Success
Console Output
Compile: 504.328ms | Execution: 69.859ms | React with ❌ to remove this embed.
Ignore that
$
, a JS-ism found it's way in lol