This solution is outdated. To rescore this solution, sign in.
-
3 Comments
Where did I do wrong?Please help me!
You fail test 2, since the vector x has length 1, you never evaluate anything in your loop. This can be fixed by initializing tf before the loop.
Look into recursive solution instead of this loop.
Why are you incrementing the solution with i=i+1? The for loop automatically increments from 1 to n-1. You are also only really testing the last two values in the vector. Your function returns false for each pair in vector but overwrites tf = false with true when it reaches the last two entries. You need to break out of the loop if you detect one false.
Suggested Problems
-
Find relatively common elements in matrix rows
2088 Solvers
-
Find state names that end with the letter A
1186 Solvers
-
718 Solvers
-
486 Solvers
-
1413 Solvers
More from this Author96
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!