Question: USE C CODE LANGUAGE TO CORRECT THE CODE Consider a non-empty string S= S[0]S[1]...S[Q-1] consisting of Q characters. The period of this string is the

USE C CODE LANGUAGE TO CORRECT THE CODE
Consider a non-empty string S= S[0]S[1]...S[Q-1] consisting of Q
characters. The period of this string is the smallest positive integer P
such that:
PQ/2 and
S(K] = S(K+P] for every K, where 0 K
For example, 8 is the period of "codilitycodilityco" and 7 is the
period of "abracadabracadabra"
A positive integer M is the binary period of a positive integer N if M is the
period of the binary representation of N.
For example, 4 is the binary period of 955, because the binary
representation of 955 is "1110111011" and its period is 4.
You are given an implementation of a function:
function solution(N);
A
This function, when given a positive integer N, returns the binary period of
N. The function returns -1 if N does not have a binary period.
For example, given N = 955 the function returns 4, as explained in the
example above.
The attached code is still incorrect for some inputs. Despite the error(s),
the code may produce a correct answer for the example test cases. The goal of the exercise is to fjnd the bug in the implementation. You can modify at most two lines. Assume that N is an integer within the range [1..1,000,000,000]
USE C CODE LANGUAGE TO CORRECT THE CODE Consider a non-empty string
Nm solution.js * 1 1 function solution(n) [ 2 2 d = new Array(30); 3 3 1 = @; 4 4 while (n > 0) { 5 5 d[1] = n % 2; 6 6 n = Math.floor(n / 2); 7 7 1 += 1; 8 8 } 9 9 for (p = 1; p

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!