Category: Java-HashMap

Minimum number of bricks that can be intersected

Given a 2D array arr[][], representing width of bricks of the same height present on a wall, the task is to find the minimum number of bricks that can be intersected by drawing a straight line from the top to the bottom of the wall.Note: A line is said to intersect a brick if it […]

Continue Reading

Check if a string can be made palindromic by swapping pairs of characters from indices having unequal characters in a Binary String

  import java.io.*;import java.util.HashMap;import java.util.HashSet;import java.util.Map;  class GFG {              public static boolean    canBecomePalindromeUtil(String S,                            String B)    {                        HashSet set = new HashSet();                  for (int i = 0; i < S.length(); i++) {                          set.add(S.charAt(i));        }                          HashMap map            = new HashMap();                  for (int i = 0; i < S.length(); i++) {            Integer k = map.get(S.charAt(i));            map.put(S.charAt(i),                    (k == null) ? 1 : k + 1);        }          boolean flag = false;                  if (S.length() % 2 == 1) […]

Continue Reading