Easy BFS Java solution 
IntuitionThe problem can be likened to a grid-based pathfinding problem where each cell has a cost (represented by moveTime). Our goal is to determine the minim
# Intuition
The problem can be likened to a grid-based pathfinding problem where each cell has a cost (represented by moveTime). Our goal is to determine the minimum time it takes to travel from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1).

We are given a matrix, where the time required to move to a neighboring cell is not uniform, and the movement rules alternate between two states, controlled by the oddEven flag. This means that the behavior of moving from one cell to another can change depending on whether the current state is "odd" or "even."

# Approach

Grid Representation:

Treat the grid as a weighted graph where each cell (i, j) represents a node, and the edges between them represent the movement to neighboring cells.
The cost of each move from one cell to another is determined by the moveTime matrix, which stores the time required to enter each cell.
Priority Queue:

Use a Priority Queue (Min-Heap) to always explore the cell with the smallest accumulated time first. This is essential for Dijkstra's algorithm.
Each element in the queue will store the current position (i, j) of the cell, the accumulated time (weight), and the current state of oddEven flag, which alternates between 1 and 2.
State Transition:

The oddEven flag alternates with each move, which may modify the cost calculation. Specifically, this flag determines the movement time: if oddEven is 1, then the movement time might be computed differently than when it's 2.
The flag is toggled every time a cell is processed to switch between two different movement behaviors.
Traversal:

Start from the top-left corner (0, 0). For each cell, explore its neighbors (up, down, left, right), calculate the new potential cost to reach each neighbor, and update the priority queue accordingly.
If the new cost to reach a neighboring cell is smaller than the current stored value, update the cell's value and push the new state into the queue.
End Condition:

If we reach the bottom-right corner (m-1, n-1), return the accumulated time.
Edge Case:

The algorithm should handle situations where the destination is unreachable, though in the problem setup, it's assumed that the destination is reachable (since it is a valid grid).

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int minTimeToReach(int[][] moveTime) {
        int m = moveTime.length;
        int n = moveTime[0].length;
        PriorityQueue<int[]> pq = new PriorityQueue<>(Comparator.comparingInt(a->a[2]));
        int matrix[][] = new int[m][n];
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                matrix[i][j] = Integer.MAX_VALUE;
            }
        }
        matrix[0][0] =0;

        pq.offer(new int[]{0,0,0,1});
        int delrow [] = new int[]{-1,0,1,0};
        int delcol [] = new int[]{0,1,0,-1};
        while(!pq.isEmpty()){
            int curr[] = pq.poll();
            int row = curr[0];
            int col = curr[1];
            int weight = curr[2];
            int oddEven = curr[3];

            if(row==m-1 && col==n-1){
                return weight;
            }
            for(int i=0;i<4;i++){

                int nrow = row+delrow[i];
                int ncol = col+delcol[i];

                if(nrow>=0 && ncol>=0 && nrow<m && ncol<n){
                    int currtime = Math.max(0,moveTime[nrow][ncol]-weight);
                    int newWeight = oddEven+currtime+weight;

                    if(newWeight<matrix[nrow][ncol]){
                        matrix[nrow][ncol] = newWeight;
                        if(oddEven==1){
                            pq.offer(new int[]{nrow,ncol,newWeight,2});
                        }else{
                            pq.offer(new int[]{nrow,ncol,newWeight,1});
                        }
                        
                    }
                }
            }

        }
        return -1;

    }
}
```
['Graph', 'Heap (Priority Queue)', 'Matrix', 'Shortest Path', 'Java']