2
public int leastBricks(List<List<Integer>> wall) {3
HashMap<Integer, Integer> edge_frequency =4
new HashMap<>(); // HashMap to store the number of common edges among the rows5
int max_frequency = 0; // Variable to store the frequency of most occuring edge7
for (int row = 0; row < wall.size(); row++) // Iterating through each row9
int edge_postion = 0; // Variable to store different edge postion11
for (int brick_no = 0;12
brick_no < wall.get(row).size() - 1;13
brick_no++) // Iterating through each brick inside a row15
int current_brick_length = wall.get(row).get(brick_no); // Length of the current brick18
+ current_brick_length; // Next Edge Position = Previous Edge Position + Current22
edge_frequency.getOrDefault(edge_postion, 0)23
+ 1); // Incrementing the Frequency of just calculated Edge Postion26
edge_frequency.get(edge_postion),27
max_frequency); // Comparing the "Frequency of just calculated Edge Postion" with28
// "Max Frequency seen till now" & storing whichever is greater.32
- max_frequency; // returning (Number of Bricks Crossed by Line) i.e. (Number of Rows in33
// Wall - Frequency of Most Occuring Edge)