Click here to Skip to main content
15,887,322 members

Comments by speed blaze (Top 3 by date)

speed blaze 7-Mar-23 9:02am View    
thanks but i'm not good at debugging but i'll do get on it
speed blaze 7-Mar-23 8:42am View    
hi thanks for your suggestions , i'm not getting paid for this code , i'm learning and improving my skills , sorry if i'm wrong in any way
speed blaze 7-Mar-23 8:40am View    
hi all , i would like thank all for your utmost support , i'm learning and i've tried it myself , here i'm new , i'll share my code here

public class Solution {

static public int minLaneChanges(int[] manholes) {

int laneChanges = 0;

// Loop through each point on the track except the last one
for (int i = 0; i < manholes.length - 1;) {
// If there is a manhole at current point, we need to jump to another lane
if (manholes[i] != 0) {
int currentLane = manholes[i];
boolean jumped = false;

// Jump to middle lane first (if not already in it) and check if we can continue on this lane
if (currentLane != 1 && manholes[i + 1] != currentLane) {
laneChanges++;
i++;
jumped = true;
}
// Check if we can continue on the side lanes without jumping again
if (!jumped) {
if (manholes[i + 1] == 0) {
i++;
} else if (manholes[i + 1] != currentLane && manholes[i + 2] == currentLane) {
i += 2;
laneChanges++;
} else {
i += 2;
laneChanges++;
}
}
} else {
i++;
}
}

return laneChanges;
}
}

// the thing is for only one test case it was giving correct outputs , rest of em it was'nt
i'm not sure which aspect do i need to correct