Make S into another binary string through changing any persona with 0 or 1 as much as Okay occasions

  

import java.util.*;

public magnificence GFG {

  

    

    public static void primary(String[] args)

    {

  

        

        String str = "akmzaxazmk";

        int Okay = 6;

  

        

        AlterString(str, Okay);

    }

  

    

    

    

    static void AlterString(String str, int Okay)

    {

  

        

        

        boolean flag = true;

  

        

        

        HashMap<Persona, Integer> map = new HashMap<>();

  

        

        for (int i = 0; i < str.duration(); i++) {

  

            

            

            

            

            

            if (map.containsKey(str.charAt(i))) {

                int finish = map.get(str.charAt(i));

                if ((finish - i) % 2 == 0) {

                    proceed;

                }

                else {

                    flag = false;

                    destroy;

                }

            }

  

            

            

            

            

            

            else {

                map.put(str.charAt(i), i);

            }

        }

  

        

        

        

        if (flag && map.measurement() <= Okay) {

            Device.out.println("YES");

            for (Map.Access<Persona, Integer> set :

                 map.entrySet()) {

                Device.out.println(

                    " " + set.getKey() + " : "

                    + ((set.getValue() % 2 == 0) ? 0 : 1));

            }

        }

        else {

            Device.out.println("NO");

        }

    }

}

Like this post? Please share to your friends:
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: