-
ArraysFundamentals
Description A delivery man has to deliver a package in 15 minutes,the address is in the coordinates [4][5], but his gps is not working right, will he arrive at time?. Every move takes a minute. Moves can be NORTH,SOUTH,EST,WEST. Representing directions ['n','s','e','w'] (No case sensitive). Also you can find a traffic jam, is represented by '/' and consumes 2 minutes.
Your task is to create a function that return true if he arrives on time, else return false.
Note: you will always receive a valid array containing a random assortment of direction letters ('n', 's', 'e', 'w' or '' only). It will never give you an empty array (return false).
Code public class ArriveAtTime{ public static boolean arriveAtTime(char [] movements){ } }
Test Cases Failed import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { void testSimple() { assertFalse(ArriveAtTime.arriveAtTime(new char[] {'n', 'E', 'N', 'E', 'W', 'S', 'W', 'N', 'W', 'S', 'S', 'E', 'S', 'E' , 'S'})); assertTrue(ArriveAtTime.arriveAtTime(new char[] {'n', 'N', 'N', 'N', 'E', 'E', 'E', 'E', 'E', 'E', 'S', 'e', 'S', 'E' , 'S'})); assertFalse(ArriveAtTime.arriveAtTime(new char[] {'n', 'N', 'N', 'N', 'E', 'e', 'E', '/', '/', '/', 'S', 'E', 'S', 'E' , 'S'})); assertTrue(ArriveAtTime.arriveAtTime(new char[] {'N', 'N', 'N', 'n', 'S', 's', 'N', 'N', 'E', 'E', '/', 'E', 'E', 'E' , 'E'})); } }
Output:
-
- All
- {{group.name}} ({{group.count}})
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report