Magicpin Coding Questions and Answers

Magicpin Coding Questions with Solutions

Here, Magicpin Coding Questions and Answers page will help you to get all the sample coding questions with solutions that are included in Online Assessment and Technical Interview of Magicpin for hiring Software Development Intern and Analyst Intern.
In the end of Magicpin Coding Questions and Answers page you will get FAQ’s related hiring process of Magicpin for hiring freshers.

magicpin-coding-questions-with-solutions

Magicpin Coding Questions with Answers

Question 1: Share Holder (R -> Hard)

Problem statement :

Ratan is a crazy rich person. And he is blessed with luck, so he always made the best profit possible with the shares he bought. That means he bought a share at a low price and sold it at a high price to maximize his profit. Now you are an income tax officer and you need to calculate the profit he made with the given values of stock prices each day. You have to calculate only the maximum profit Ratan earned.
Note that:
Ratan never goes into loss.

Example 1 :

Price=[1,6,2]
Ratan buys it on the first day and sells it on the second.

Example 2 :

Price=[9,8,6]

The Price always went down, Ratan never bought it.

Input Format:
First line with an integer n, denoting the number days with the value of the stack
Next n days, telling the price of the stock on that very day.

Output Format:
Maximum profit done by Ratan in a single line.
Constraints:
Number of days <=10^8

Sample Input for Custom Testing

STDIN
———–
7
1
9
2
11
1
9
2

Sample Output

10

Explanation

The maximum profit possible is when Ratan buys it in 1 rupees and sells it in 11.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Question 02 : Device Name System

Problem statement: Rocky is a software engineer and he is creating his own operating system called “myFirst os”. myFirst os is a GUI (Graphical user interface) based operating system where everything is stored in files and folders. He is facing issues on  creating unique folder names for the operating system . Help rocky to create the unique folder name for it’s os.If folder name already exists in the system and integer number is added at the name to make it unique. The integer added starts with 1 and is incremented by 1 for each new request of an existing folder name. Given a list of folder names , process all requests and return an array of corresponding folder names.

Example 

  • n=5
  • foldername= [‘home’ , ‘myfirst’ ,’downloads’, ‘myfirst’, ‘myfirst’]
  • Foldername[0] = ‘home’ is unique.
  • Foldername[1] = ‘myfirst’ is unique.
  • foldername [2] =’downloads’ is unique.
  • Foldername[3] =’myfirst’ already exists in our system. So Add1 at the end of the folder name i.e foldername[3] =”myfirst1″
  • Foldername[4 ]=’myfirst’ also already exists in our system.So add 2 at the end of the folder name i.e. foldername[4]=”myfirst2″.

Function description 

  • Complete the function folderNameSystem In the editor below
  • folderNameSystem has the following parameters
  • string foldername[n]: an array of folder name string in the order requested

Returns:

  • String[n]:  an array of strings usernames in the order assigned

Constraints

  •     1<=n<=10^4
  •     1<=length of foldername[i]<20
  •     foldername[i] contains only lowercase english letter in the range ascii[a-z]

Input Format:

  • The first line contains an integer n , denoting the size of the array usernames Each line i of the n subsequent lines (where i<=0<=n) contains a string usernames[i] representing a username request in the order received.

Sample case 0

  • 4
  • home 
  • download
  • first
  • first

Sample Output 0

  • home
  • download
  • first
  • first1

Explanation 0

  •    foldername[0] = ‘home’ is unique
  •    foldername[1]=’download’ is unique
  •    foldername[2]= ‘first’ is unique
  •    foldername[3]=’first’ is already existing . so add 1 to it and it become first1

Question 3 : Stars Between Bars

Problem statement :

Given a string s consisting of stars “*” and bars “|” ,an array of starting indices starIndex,and an array of ending indices endIndex,determine the number of stars between any two bars within the substrings between the two indices inclusive . NOTE that in this problem indexing starts at 1.

  • A Star is represented as an asterisk [*=ascii decimal 42]
  • A Bar is represented as a Pipe [“|”=ascii decimal 124]

Example :
s=’|**|*|’
startIndex=[1,1]
endIndex=[5,6]

For the first pair of indices (1,5) the substrings is “|**|*” . There are 2 stars between a pair of bars
For the second pair of indices (1,6) the substring is “|**|*|” and there are 2+1=3 stars in between the bars.
Both of the answers are returned to the array [2,3].

Constraints :
int [n];each element[i] answers the query of startIndex[i] to endindex[i]

Constraints
1<=n<=105
1<=StartInde[i]<=endIndex[i]
Each Character of s is either “*” or “|”

>Input Format for Custom testing
First line contains a string S the next line contains an integer n , the no.of elements in startIndex. Each line i of the n subsequent lines contains an integer of startIndex.the next line contains an integer n , the no.of elements in endIndex. Each line i of the n subsequent lines contains an integer of endindex
>Sample Case 0

Sample Input for Custom Testing
*|*| → s=”*|*|”
1 → startindex[] size=1
1 → startindex= 1
1 → endindex[] size=1
3 → endindex=3
Sample output  :
0
Explanation :
The substring from index =1 to index=3 is “*|*” . there is no consecutive pair of bars in this string.

Question 4 :Vampire Battle (R->Medium)

Problem statement :

Stephan is a vampire. And he is fighting with his brother Damon. Vampires get energy from human bloods, so they need to feed on human blood, killing the human beings. Stephan is also less inhuman, so he will like to take less life in his hand. Now all the people’s blood has some power, which increases the powers of the Vampire. Stephan just needs to be more powerful than Damon, killing the least human possible. Tell the total power Steohan will have after drinking the bloods before the battle.
Note that: Damon is a beast, so no human being will be left after Damon drinks everyone’s blood. But Stephan always comes early in the town.

Input Format :
First line with the number of people in the town, n.
Second line with a string with n characters, denoting the one digit power in every blood.

Output Format :
Total minimum power Stephan will gather before the battle.

Constraints :
n<=10^4

Sample input :
6
093212

Sample output:
9

Explanation :
Stephan riches the town, drinks the blood with power 9. Now Damon cannot reach 9 by drinking all the other bloods.

Question 5 : Last student’s ID

There is an id code that is supposed to be given to all the aspirants of an exam. It is actually a substring of a given string. That means, the authority takes a string and then assigns all the unique substrings to all the students. Suppose there is a string “abcde”, so the ids of the students will be “a”, “ab”, ”abc”, ”abcd”, ”abcde”, ”b”, ”bc”, ”bcd”, ”bcde”, ”c”, ”cd”, ”cde”, ”d”, ”de”, ”e”.
The students are standing in a line according to the lexicographic order of their given ids. You have to find out the id of the last student for the given input string from which the ids are generated and then arranged in lexicographic order.

Input Format:

  • Single line with the id generating string

Output format:

  • The last id as per lexicographical order.

Constraints:

  • Number of characters in the string<=10^9

Sample Input:

abdc

Sample output:

dc

Explanation:

The last student as per lexicographical order will be with the id dc. The lexicographical order for adbc will be :
a
ab
abd
abdc
b
bd
bdc
c
d
dc

Question 6 : Elements of Matrix

Problem Statement 

You are required to input the size of the matrix then the elements of matrix, then you have to divide the main matrix in two sub matrices (even and odd) in such a way that element at 0 index will be considered as even and element at 1st index will be considered as odd and so on. then you have sort the even and odd matrices in ascending order then print the sum of second largest number from both the matrices

Example

  • enter the size of array : 5
  • enter element at 0 index : 3
  • enter element at 1 index : 4
  • enter element at 2 index : 1
  • enter element at 3 index : 7
  • enter element at 4 index : 9

Sorted even array : 1 3 9
Sorted odd array : 4 7

7

Question 7 : Spiral Matrix

Problem Statement :

You will be given a 2d matrix. Write the code to traverse the matrix in a spiral format. Check the input and output for better understanding.

Sample Input :
Input :
5 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20

Output :

1 2 3  4 5 6 7 8 9 10 11 12 13 14  15 16 17 18 19 20

Question 8 : Minimum Occurrence (R->Medium)

Problem Statement  :
Given a sting , return the character that appears the minimum number of times in the string. The string will contain only ascii characters, from the ranges (“a”-”z”,”A”-”Z”,0-9), and case matters . If there is a tie in the minimum number of times a character appears in the string return the character that appears first in the string.

Input Format:
Single line with no space denoting the input string.

Output Format:
Single character denoting the least frequent character.

Constraints:
Length of string <=10^6

Sample Input:
cdadcda

Sample Output:
c

Explanation:
C and A both are with minimum frequency. So c is the answer because it comes first with less index.

 

Question 9 : Sum of K Farthest items

Problem Statement  :

You are given an array of length “len” ,another item called k and an integer value x. Your job is to find the sum of k farthest items in the array from x.

First line has len, k and x respectively
2nd line has the array

Example :

Input :
5 3 20
21 4 15 17 11

Output :
30

4, 15 and 11 are farthest from 20. Thus, their sum will be the answer.

Question 10: Match

Problem Statement :
The number of goals achieved by two football teams in matches in a league is given in the form of two lists. For each match of team B. Compute the total number of matches of team A where team A has scored less than or equal to the number of goals scored by team B in that match.

Example : 
team A =[ 1,2,3]
team B =[ 2,4]
Team A has played three matches and has scored team A =[1,2,3] goals in each match respectively. Team B has played two matches and has scored team B = [2,4] goals in each match respectively. For 2 goals scored by team B in its first match, team A has 2 matches with scores 1,2 and 3 hence , the answer is [2,3].

Function Description :

Complete the function counts in the editor below.

Counts has the following parameters:
int teamA(n): First array of positive integers
int teamB(m): Second array of positive integers

Return :
int(m): an array of m positive integers, one for each teamB[i] representing the total number of elements from teamA[j] satisfying teamA[j]<_ teamB[i] where 0<_j<n and 0<_i< m, in the given order.

Constraints :
2<_n, m<_10^5
1<_ teamA[j]<_10^9,where 0<_j<n.
1<_ teamB[i]<_10^9,where 0<_j<m

Input format for custom Testing :
Input from stdin will be processed as follows and passed to the functions.

The first line contains an integer n, the number of elements in teamA.
The next n lines each contain an integer describing teamA[j] where 0<_j<n.
The next line contains an integer m, the number of elements in teamB.
The next m lines each contain an integer describing teamB[i]where 0<_i<m.

Sample input 0 :
4 -> teamA[] size n = 4
1 -> teamA = [1,4,2,4]
4
2
4
2-> teamB [] size m = 2
3-> teamB = [3,5]
5

Sample ōutput 0 :
2
4

Explanation 0 :
Given values are n =4, team A = [1,4,2,4], m= 2, and teamB = [3,5].
For teamB[0] = 3, we have 2 elements in teamA(teamA[0] = 1 and teamA[2] = 2) that are <_ teamB[0].
For teamB[1] = 5, we have 4 elements in teamA(teamA[0] = 1, teams[1] =4, teamA[2] = 2, and teamA[3] =4) that are <_teamB[1].
Thus , the function returns the array [2,4] as the answer.

FAQ's related Magicpin Hiring Process

Question 1: What kind of company is Magicpin?

MagicPin is a tool that helps people find great places to shop and enjoy different services. With its app, users can easily locate local cafes, dimsum spots, fashion boutiques, fancy spas, gyms, and even get discounts at grocery stores and more.

Question 2: What is the eligibility criteria for Magicpin hiring process?

Magicpin has set different eligibility criteria for SDE role and Analyst role such as:

  • For SDE role : 
    1. Minimum 8 C.G.P.A or Equivalent % throughout academic.
    2. B.TechCS, IT or ECE.
    3. No current backlog allowed.
  • For Analyst role :
    1. Minimum 7.5 C.G.P.A or Equivalent % throughout academic.
    2. B.TechCS, IT or ECE.
    3. No current backlog allowed.
    4. Applicants must have good command in Python and SQL.
Question 3: What is the recruitment process of Magicpin?

Magicpin recruitment process includes following steps:

  1. Resume Shortlisting
  2. Online Assessment
  3. Technical Interview
  4. HR Interview
Question 4: What are the skills required for Analyst Intern in Magicpin?

For Magicpin Analyst Intern role you must have good knowledge in following skills:

  1. Python
  2. Advanced Excel
  3. SQL 
  4. DBMS
Question 5: What is the salary in MagicPin?
  1. For Analyst Intern = On an average of ₹ 4.5 LPA to ₹ 6 LPA.
  2. For SDE Role = Ranges between ₹ 7 LPA to 11 LPA 

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription