Skip to content

Commit

Permalink
Create 1503_Last_Moment_Before_All_Ants_Fall_Out_of_a_Plank.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhuzaima authored Nov 4, 2023
1 parent 43476c6 commit 03e4c9b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 1503_Last_Moment_Before_All_Ants_Fall_Out_of_a_Plank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// id: 1503
// Name: Last Moment Before All Ants Fall Out of a Plank
// link: https://leetcode.com/problems/last-moment-before-all-ants-fall-out-of-a-plank/
// Difficulty: Medium

class Solution {
public int getLastMoment(int n, int[] left, int[] right) {
// calcualte time taken by each ant to move to edge

// store largest
int result = 0;

for (int l: left) {
if (l > result) result = l;
}

for (int r: right) {
if (n-r > result) result = n-r;
}

return result;
}
}

0 comments on commit 03e4c9b

Please sign in to comment.