DATA STRUCTURE
Programming and Technical
Programming
Problem Statement:
Problem statement is very easy . On a positive integer, you can perform any one of the following 3 steps.
1.) Subtract 1 from it. ( n = n - 1 )
2.) If its divisible by 2, divide by 2. ( if n % 2 == 0 , then n = n / 2 )
3.) If its divisible by 3, divide by 3. ( if n % 3 == 0 , then n = n / 3 )
Given a positive integer n and you task is find the minimum number of steps that takes n to one .
Read Solution (Total 0)
DATA STRUCTURE Other Question
EXAMPLE:
Input=['1','0','1','2','3','0','3','4','0']
Output:
['1', '1', '2', '3', '3', '4', '0', '0', '0']
// Function to move all zeros present in the array to the end
void reorder(int A[], int n)
{
// k stores index of next available position
int k = 0;
// do for each element
for (int i = 0; i < n; i++)
{
// if current element is non-zero, put the element at
// next free position in the array
if (A[i] != 0)
A[k++] = A[i];
}
// move all 0's to the end of the array (remaining indices)
for (int i = k; i < n; i++)
A[i] = 0;
}
// Move all zeros present in the array to the end
int main(void)
{
int A[] = { ..... };
int n = sizeof(A) / sizeof(A[0]);
reorder(A, n);
for (int i = 0; i < n; i++)
printf("%d ", A[i]);
return 0;
}
Which of the following data structure is better for storing the sorted data on which often insert and deletion operations are performed?
A. Linked list
B. Queue
C. Array
D. Doubly linked-list