You are on page 1of 3

6/16/2020 Newton School

Newton School

Weekly Assignment

Important points to take care

Java coders: You need to have a Main class in your program with a main function

C coders: You need to return int for main function

Question 1
Season Of Love
In this season of love, everyone wants to surprise each other.
You are also super excited and you wish to buy roses of 3 different colors. You always buy roses in order,
white, yellow, red.
So if you buy 7 roses, they will be "white, yellow, red, white, yellow, red, white".

You need to find the number of yellow roses that you will buy?

Edit

Question 2
Buildings
There are N buildings in a row with different heights(H[i]).
You are viewing the buildings from the left and can see the roof of a building, if no building to the left of
that building has height greater than equal to height of that building.
You are asked the number of buildings whose roofs you can see.

Edit

Question 3
Circular River
There is circular river of length K. There are N cities on the banks of the river. The position p(i) of the i-th
city is defined as its distance from the topmost point of the river in the clockwise manner.
You are given the positions of all the N cities, your task is to find the minimum distance you need to travel
to visit all the N cities. You can start at whichever point you like, and can move both clockwise and
anticlockwise around the river.

See sample for better understanding.

Edit

Question 4
Mutating Array
Given an integer array arr and a target value K, return the integer value V such that when we change all the
integers larger than V in the given array to be equal to V, the sum of the array gets as close as possible (in
absolute difference) to K.

In case of a tie, return the minimum such integer.

Note: the answer is not necessarily a number from arr.

Edit

Question 5
Get the Shadow
Given an unsorted array A[] of size N of positive integers. One number 'a' from set {1, 2, …N} is missing and
one number 'b' occurs twice in array. The task is to find the repeating and the missing.

Edit
https://my.newtonschool.co/course/j5rrobkdxa/assignment/2srkuqplsv/ 1/3
6/16/2020 Newton School

Question 6
Odd Inception
Siddharth, a great entrepreneur, chooses a person as an intern if he/she good at maths. Thus Sid gives a
simple maths problem to the candidate based on which he decides to who is gonna get the offer. Below is
the description of the problem asked by Sid
Given arr A[] containing N positive integers. The task is to check whether it is possible to divide the given
array into an odd number of non-empty subarrays each of odd length such that each sub-array starts
and ends with an odd number. If it is possible to divide the array then print "YES" otherwise "NO".

Note: Don't forget that the complete array is also considered as a subarray

Start Now

Question 7
Simple Arrangement
Given an array A (0 indexed) of n integers from 0 to n-1 (each integer exactly once), output an array such
that A[i] becomes A[A[i]].

Make sure you don't use extra memory than array itself.

Edit

Question 8
Equalise the Array
You are given an array Arr of n integers. You can perform the following operations on the array any number
of times.
Operation 1: Add or Subtract 2 from any element of the array any number of times
Operation 2: Remove a number from the array
Your aim is to make all the elements of the array equal after performing the above operations any number
of times. Report the maximum size of the array possible.

Edit

Question 9
Decompress Encoded Array
We are given a list Arr[] of integers representing a list compressed with run-length encoding.

Consider each adjacent pair of elements [freq, val] = [Arr[2*i], Arr[2*i+1]] (with i >= 0). For each such pair,
there are freq elements with value val concatenated in a subarray. Concatenate all the subarray from left to
right to generate the decompressed array.

Print the decompressed array.

Edit

Question 10
Simple Paired Sum
Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number
represents the pair-wise sum of consecutive elements of the array A.

In simple terms print (A[1]+A[2]), (A[3]+A[4]), ..., (A[N-1]+A[N]).

Edit

Question 11
Simple Paired Product
Given an array A of size N (N is always even), you need to find exactly (N/2) numbers where each number
represents the pair-wise product of consecutive elements of the array A.

In simple terms print (A[1]*A[2]), (A[3]*A[4]), ..., (A[N-1]*A[N]).


https://my.newtonschool.co/course/j5rrobkdxa/assignment/2srkuqplsv/ 2/3
6/16/2020 Newton School

(Use long long int to avoid overflow)

Edit

Question 12
Array construction
You are given two arrays - value and frequency both containing N elements.
There is also a third array C which is currently empty. Then you perform N insertion operation in the array.
For ith operation you insert value[i] to the end of the array frequency[i] number of times.
Finally you have to tell the kth smallest element in the array C.

Edit

© 2020 Incanus Technologies Pvt Ltd For any queries, you can reach us at Follow us on
All rights reserved. support@newtonschool.co

https://my.newtonschool.co/course/j5rrobkdxa/assignment/2srkuqplsv/ 3/3

You might also like