Hi, I am trying to return true if a sub-array exists at given index (idx), false otherwise. For example:
if idx = -1, return false since data[-1] is out of bounds
* if idx = 0, return true since data[0] refers to the first sub-array
* if idx = 1, return true since data[1] refers to the second sub-array
* ...
* if idx = data.length - 1, return true since data[data.length - 1] refers to the last sub-array
* if idx = data.length, return false since data[data.length] is out of bounds
*/
I have attempted the question but cannot seem to past the tests on eclipse. I am wondering what I am doing wrong?
public boolean isValidSubsetIndex(int idx) {
if(idx <= -1 || idx == data.length - 1 ) {
return true;
}else {
return false;
}
}
if idx = -1, return false since data[-1] is out of bounds
* if idx = 0, return true since data[0] refers to the first sub-array
* if idx = 1, return true since data[1] refers to the second sub-array
* ...
* if idx = data.length - 1, return true since data[data.length - 1] refers to the last sub-array
* if idx = data.length, return false since data[data.length] is out of bounds
*/
I have attempted the question but cannot seem to past the tests on eclipse. I am wondering what I am doing wrong?
public boolean isValidSubsetIndex(int idx) {
if(idx <= -1 || idx == data.length - 1 ) {
return true;
}else {
return false;
}
}