✅✅👌👌GREAT SOLUTION ,UNDERSTAND BETTER, EASY APPROACH💯💯
PRETTY EASY APPROACH FOR BETTER UNDERSTANDING THE SLIDING WINDOW CONCEPT (BEGINNER FRIENDLY)\n\n\npublic int minSwaps(int[] a) {\n\tint windowSize = 0;\n\tfor(i
***_PRETTY EASY APPROACH FOR BETTER UNDERSTANDING THE SLIDING WINDOW CONCEPT (BEGINNER FRIENDLY)_***\n\n```\npublic int minSwaps(int[] a) {\n\tint windowSize = 0;\n\tfor(int x : a){\n\t\twindowSize = x == 1 ? windowSize+1 : windowSize; \n\t} \n\tif (windowSize ==a.length)return 0;\n\n\tint back= 0 ;int front=windowSize - 1 ;\n\tint initialCount =0;\n\tfor(int i =0 ; i<= front; i++){\n\t   if(a[i]==0) initialCount++;\n\t}\n\tback++;\n\tfront++; \n\tint ans = initialCount;\n\twhile(back<a.length){\n\t\t if(front==a.length)front=0;\n\t\tinitialCount = giveMeCounts(a,back,front,initialCount);\n\t\t ans = Math.min(ans , initialCount);\n\t\tback++; front++;\n\t}\n\treturn ans;\n}  \npublic int giveMeCounts(int []a , int b, int f,int initialCount){\n\n\tinitialCount = a[b-1]==0 ? initialCount - 1 :initialCount;\n\tinitialCount = a[f]== 0 ? initialCount+1:initialCount;\n   //  System.out.println(b + " "+ f + "-" + initialCount);\n\t return initialCount;\n}\n}\n```\n\n***PLEASE UPVOTE IF U LIKE***\n\n
['Java']