KNOWLEDGE OF ARRAY 1D AND 2D
Given a Binary String of length L and N number of other binary strings of the same length L we have to Find the string which has the minimum difference with the original string.
Store each string within an array. For each string calculate the difference by comparing it to the original string and store each difference into a different array then. Find the minimum of the array and the index of the minimum element and store the index into a variable and then print the string associated with the found index.
Store Orignal string into a variable and then N no of String into an array of strings.Now we’ll define a variable, which will be used to calculate the difference between the orignal string and ith string of the string array. For ith string of the string array, we have to compare jth letter of the string with jth letter of the orignal string and if both letters are not same then well increase the variable count and repet this step for L times for a string, and then store the count variable into an array of integers. repeat the same process for N strings. We’ll get an array of N elements each containing an integer denoting the value of difference between the ith string and orignal string. Then we’ll find the minimum element of the difference array and the index K of the minimum element i. At last, print the Kth element from string array.
for i=0 to n: count=0 for j=0 to l: if strings*[j]==orignal_string[j]: count+=1 difference*=count
Author’s solution can be found here.