A chocolate factory is packing chocolates into the packets. The chocolate packets here represent an array arrt of N number of integer values. The task is to find the empty packets(0) of chocolate and push it to the end of the conveyor belt(array).
For Example:
N=7 and arr = [4,5,0,1.9,0,5,0].
There are 3 empty packets in the given set. These 3 empty packets represented as O should be pushed towards the end of the array.
Example 1:
Input:
7 – Value of N
[4,5,0,1,0,0,5] – Element of arr[O] to arr[N-1],While input each element is separated by newline
Output:
4 5 1 9 5 0 0
Example 2:
Input:
6
— Value of N.
[6,0,1,8,0,2] – Element of arr[0] to arr[N-1], While input each element is separated by newline
Output:
6 1 8 2 0 0
L=list(map(int,input('Enter the orders : ').split(' ')))# or you can get the N value and get the input using for loop L1=[] temp=0 for i in L: if i!=0: L1.append(i) else: temp+=1 if temp!=0: for i in range(temp): L1.append(0) print(L1)
Input_1:
4 5 0 1 0 0 5
Output:
[4, 5, 1, 5, 0, 0, 0]
Input_2:
6 0 1 8 0 2
Output:
[6, 1, 8, 2, 0, 0]
Input_3:
1 2 3 0 3 4 0 1
Output:
[1, 2, 3, 3, 4, 1, 0, 0]
Input_4:
1 0 2 0 4 0 6 6
Output:
[1, 2, 4, 6, 6, 0, 0, 0]
More Q
- Find the majority element appearing more than n/2 times
- Return an array of the squares of each number.
- Highest factor in addition.
- Find the empty packets(0) of chocolate and push it to the end of the conveyor belt(array).
- Every element in array appears twice.Find that single one.
- Find the duplicate letters in string. Same to do in dictionary way.
- Find minimum number of edits (operations) required to convert ‘str1’ into ‘str2’.
- Return the maximum number you can get by changing at most one digit.
- Sed Commands – Ranges of lines.
- Find the kth smallest element in the given 2D array.
- Find all elements that appear more than [n/3] times.
- Write a function to return true if s2 contains the permutation of s1.
- Sort the array into a wave like array.
- Re-order array, such that
nums[0] < nums[1] > nums[2] < nums[3]...
. - Given the coordinates, return true if the four points construct a square.
- Minimum Distance Between Words of a String.
- Return the shortest distance between these two words.
- Write a program to find the n-th ugly number.
- Check if array could become Non – Decreasing array.
- Find the minimum area of a rectangle that can be formed from given points.