DFG Back-End Engineer Hiring Test With Answers

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10
At a glance
Powered by AI
The document discusses programming interview questions and challenges related to data structures, algorithms, and problem solving. It provides examples of questions on topics like arrays, searching, stacks, and REST APIs.

The document provides programming problems and their explanations to help prepare for a back-end engineering interview. It includes questions on arrays, searching, stacks, and REST APIs.

The minX function takes in an array and returns the minimum integer value of x that satisfies the running sum condition where the running sum of x plus each array element never drops below 1 when traversing from left to right.

12/11/2019 DFG Back-End Engineer Hiring Test | Programming problems and challenges | HackerRank

DFG Back-End Engineer Hiri… 133 minutes

Question - 1 SCORE: 50 points


Picking Tickets

Easy Data Structures Arrays Algorithms Problem Solving Core Skills

Consider an array of n ticket prices, tickets. A number, m, is defined as


the size of some subsequence, s, of tickets where each element covers
an unbroken range of integers. That is to say, if you were to sort the
elements in s, the absolute difference between any elements j and j + 1
would be either 0 or 1. For example, tickets = [8, 5, 4, 8, 4] gives us
sorted subsequences {4, 4, 5} and {8, 8}; these subsequences have m
values of 3 and 2, respectively.
 
Function Description
Complete the function maxTickets in the editor below. The function
must return an integer that denotes the maximum possible value of m.
 
maxTickets has the following parameter(s):
    tickets[tickets[0],...tickets[n-1]]:  an array of integers
 
Constraints
1 ≤ n ≤ 105
1 ≤ tickets[i] ≤ 109
 

Input Format For Custom Testing

The first line contains an integer, n, that denotes the number of


elements in tickets.

Each line i of the n subsequent lines (where 0 ≤ i < n) contains an


integer that describes tickets[i].
 

Sample Case 0

Sample Input 0

4
4
13
2
3

 
Sample Output 0

 
Explanation 0
tickets = [4, 13, 2, 3]
There are two subsequences of tickets that contain consecutive Help
integers: {2, 3, 4} and {13}. These subsequences have m values of 3

1/10
and 1, respectively. Return the maximum value of m, which is 3.
12/11/2019 DFG Back-End Engineer Hiring Test | Programming problems and challenges | HackerRank

Question - 2 SCORE: 75 points


Minimum Start Value

Search Binary Search Medium Algorithms Problem Solving Core Skills

Start with an initial guess for x, an integer, and a given array of
integers. Calculate a running sum of x plus each array element, from
left to right. The running sum must never get below 1.  Given an array
of integers, determine the minimum value of x. 
 
For example, arr = [-2, 3, 1, -5].  If x = 4, the following results are
obtained:

Running
sum arr[i]
--------- --------
4 -2
2 3
5 1
6 -5
1

 
The final value is 1, and the running sum has never dropped below 1. 
The minimum starting value for x is 4.
 
Function Description
Complete the function minX in the editor below. The function must
return the minimum integer value for x.
 
minX has the following parameter(s):
    arr[arr[0],...arr[n-1]]:  an array of integers
 
Constraints
1 ≤ n ≤ 105
−100 ≤ arr[i] ≤ 100
 

Input Format for Custom Testing

Input from stdin will be processed as follows and passed to the


function.
 
The first line contains an integer n, the size of the array arr.
Each of the next n lines contains an integer arr[i].
 

Sample Case 0

Sample Input 0

10
-5
4
-2
3
1
-1
2/10
-6
12/11/2019 -1 DFG Back-End Engineer Hiring Test | Programming problems and challenges | HackerRank
0
5

 
Sample Output 0

 
Explanation 0

Running
sum arr[i]
--------- --------
8 -5
3 4
7 -2
5 3
8 1
9 -1
8 -6
2 -1
1 0
1 5
6

The minimum starting value for x is 8.

Sample Case 1

Sample Input 1

5
-5
4
-2
3
1

 
Sample Output 1

 
Explanation 1
 

Running
sum arr[i]
--------- --------
6 -5
1 4
5 -2
3 3
6 1
7

Sample Case 2

Sample Input 2

10
-5
4
-2
3
1
3/10
-1
12/11/2019 -6 DFG Back-End Engineer Hiring Test | Programming problems and challenges | HackerRank
-1
0
-5

 
Sample Output 2

13

 
Explanation 2
 

Running
sum arr[i]
--------- --------
13 -5
8 4
12 -2
10 3
13 1
14 -1
13 -6
7 -1
6 0
6 -5
1

Question - 3 SCORE: 75 points


Transaction Statements for Users

REST API GET Back-End Development Medium JSON

In this challenge, use the HTTP GET method to retrieve information


from a database of Card Transactions records for users. Query
https://jsonmock.hackerrank.com/api/transactions/search?txnType=txn
where txn is the transaction type of the record passed to the function.
This will return all records that have the given transaction type. The
query response is paginated and can be further accessed by appending
to the query string &page=num where num is the page number.
 
The query response from the API is a JSON response with the
following five fields:
page: the current page.
per_page: the maximum number of results per page.
total: total number of records in the search result.
total_pages: the total number of pages which must be queried to
get all the results.
data: an array of JSON objects containing transaction records
 
The data field in the response contains a list of the transaction records,
with each transaction record following the below-described schema :
 
id: the unique ID of the record
timestamp: the timestamp when the record was generated
(In UTC milliseconds)

4/10
userId: the user id of the user who performed the transaction
12/11/2019 userName: the  user name
DFG Back-End of theHiring
Engineer user who
Testperformed the problems and challenges | HackerRank
| Programming
transaction
txnType: the transaction type of the
transaction, either debit or credit
amount: the transaction amount stored as a string with the
currency structure and prefixed with the $ sign, e.g. "$2,273.95".
location: the object containing the location description of the
transaction
location.id: the id of the location where the transaction took
place
location.address: the address of the location where the
transaction took place
location.city: the city where the transaction took place
location.zipCode: the zip code of the location where the
transaction took place
ip: the IP address of the device which was used to perform the
transaction
 
Given the locationId, locationId, and the provided transaction type,
txnType, return a 2d array containing the total amount transacted by
each user at the given locationId.
The array will be in the format [ [1, 1200] , [2, 2333] ]  where the item at
index 0 in the inner array denotes the id of the user and item at index 1
denotes the total amount transacted (either debit or credit based on
input txnType). The items in the outer array should be sorted by the ids
of the user. Note that the search is not case sensitive.
 
 
Function Description
Complete the function getTransactions in the editor below.
 
getTransactions has the following parameter(s):
    int locationId: the id of the location by which record will be fetched,
to be matched with the property location.id
    string txnType: the transaction type to filter the records on
Returns:
    [int[]]: a 2d array containing the total amount transacted by each
user at the given location id. If no records are found matching the filter
criteria, it should return [[-1, -1]].
 
Note: The total amount should be rounded off to 2 places after the
decimal. It can also be returned as a string.
 

Input Format For Custom Testing

The first line contains an integer, locationId, the id of the location of


interest
The second line contains a string, txnType, the transaction type to
filter for

Sample Case 0

Sample Input For Custom Testing

STDIN Function
----- --------
1 → locationId = 1
debit → txnType = 'debit'

Sample Output
5/10
1 13200.08
12/11/2019 2 DFG Back-End Engineer Hiring Test | Programming problems and challenges | HackerRank
16745.72
3 18859.77
4 10360.32

Given txnType = debit the query is


https://jsonmock.hackerrank.com/api/transactions/search?
txnType=debit and the response includes:

[
{ id: 1,
userId: 1,
userName: 'John Oliver',
timestamp: 1549536882071,
txnType: 'debit',
amount: '$1,670.57',
location: { id: 7,
address: '770, Deepends, Stockton Street',
city: 'Ripley',
zipCode: 44139
},
ip: '212.215.115.165'
}...
]

Given the response from the API for txnType = 'debit', filter the
records. After filtering the data to find all the records which belong
to location.id = 1, find the total amount spent by each user. The final
values for user 1 is 11590.28, for user 2 is 17410.38 and so on.
Finally create the 2d array containing the answer [[1, 13200.08], [2,
16745.72], [3, 18859.77], [4, 10360.32]] which is returned.

Question - 4 SCORE: 5 points


Replication and Partitioning

Replication Medium Distributed Systems

Replication and partitioning are two common ways to distribute data


across multiple machines/nodes. Which of the following are true?

  
Both replication and partitioning can be crucial in improving the performance of delivering
data on request.

   Replication and partitioning cannot be used together.

  
In leader-based replications, one of the nodes stores all the data. Only when needed, the
other nodes ask the leader to deliver data that they do not have.

  
Using hash-based partitioning usually has a disadvantage in the performance of range-
based queries

Question - 5 SCORE: 5 points


Message Queues

6/10
Medium Distributed Systems Distributed Message Queue
12/11/2019 DFG Back-End Engineer Hiring Test | Programming problems and challenges | HackerRank

In a modern distributed system, message queues are important


components that provide communication between and coordination of
the parts of the system. Which of the following are true?

   Message queues make the system more decoupled.

   Message queues increase the reliability of the system.

  
Message queues, in general, decrease the overall performance of the system.

   Message queues increase the complexity of the system architecture.

Question - 6 SCORE: 5 points


REST Server Response

Easy REST API

Which of the following is (are) valid server response formats?

   XML

   JSON

   CSV

   None of these

Question - 7 SCORE: 5 points


Good URI Design

URI Easy REST API

Which of the following rules should be followed to design a good URI?

   URIs should never be changed

   URIs must be constructed by the client

   URIs should be short in length

   URIs should be case-sensitive

   HTTP verbs should be used instead of operation names in URIs

   Use spaces when designing a URI

   Redirection must be used if a change in URI is required

7/10
Question - 8 SCORE: 5 points

12/11/2019 Restrictions
DFGofBack-End
RESTful web services
Engineer Hiring Test | Programming problems and challenges | HackerRank

Medium

Select all statements below that are major constraints according to the


REST specifications.

  
There should be separate concerns for each server and client which will help to maintain
the modularity within the application. This will also reduce the complexity and increase
the scalability.

  
The client-server communication should be stateless, which means no previous
information is used and the complete execution is done in isolation. In cases of failure, it
also helps the client to recover.

  
In client-server communication, the HTTP response should be cacheable so that when
required, a cached copy can be used which in turn enhances the scalability and
performance of the server.

  
Client-server communication should be done on a layered system. Thus the client should
only have knowledge about the intermediate level with which communication is being
done.

Question - 9 SCORE: 5 points


Architectural Constraints of REST

Medium REST API

Select the Architectural Constraints of REST API: 

   Uniform interface

   Stateless

   Cacheable

   Layered system

Question - 10 SCORE: 100 points


Super Stack

Dynamic Programming Hard Algorithms Problem Solving Stacks Core Skills

Implement a stack that accepts the following commands and performs


the operations described:
push v: Push integer v onto the top of the stack.
pop: Pop the top element from the stack.
inc i v: Add v to each of the bottom i elements of the stack.

8/10
 
12/11/2019 After eachDFG Back-End
operation, Engineer
print Hiring
the value at theTest
top |ofProgramming problems and challenges | HackerRank
the stack. If the
stack is empty, print the string EMPTY. For example:

op stack top (print this)


push 4 [4] 4
push 5 [4,5] 5
inc 2 1 [5,6] 6
pop [5] 5
pop [] EMPTY

 
 
Function Description
Complete the superStack function in the editor below. After each
operation, print the value of the stack's top element on a new line. If
the stack is empty, print EMPTY instead.
 
superStack has the following parameter(s):
    operations[operations[0],...operations[n-1]]:  an array of strings
 
Constraints
1 ≤ n ≤ 2 × 105
-109 ≤ v ≤ 109
1 ≤ i ≤ |S|, where |S| is the size of the stack at the time of the
operation.
It is guaranteed that pop is never called on an empty stack.
 

Input Format for Custom Testing

Input from stdin will be processed as follows and passed to the


function.
 
The first line contains an integer n, the size of the array operations.
The next n lines each contain a string, operations[i] .

Sample Case 0

Sample Input 0

12
push 4
pop
push 3
push 5
push 2
inc 3 1
pop
push 1
inc 2 2
push 4
pop
pop

 
Sample Output 0

4
EMPTY
3
5
2
3
6

9/10
1
12/11/2019 1 DFG Back-End Engineer Hiring Test | Programming problems and challenges | HackerRank
4
1
8

 
Explanation 0
The diagram below depicts the stack after each operation:

After performing each operation, print the value at the top of the
stack on a new line.
 
Start with an empty stack, S, expressed as an array where the lowest
indexed element is the bottom of the stack and the highest is its top.
Perform n = 12 operations as given:
1. push 4: Push 4 onto the stack, so S = [4]. Print the top (rightmost)
element, 4, on a new line.
2. pop: Pop the top element from top of the stack, so S = []. Print
EMPTY on a new line.
3. push 3: Push 3 onto the stack, S = [3]. Print 3, and the top of the
stack after each of the following operations.
4. push 5: Push 5 onto the stack, S = [3, 5].
5. push 2: Push 2 onto the stack, S = [3, 5, 2]. 
6. inc 3 1: Add v = 1 to the bottom i = 3 elements of the stack, S = [4,
6, 3]. 
7. pop: Pop the top element from the stack, S = [4, 6]. 
8. push 1: Push 1 onto the stack, S = [4, 6, 1]. 
9. inc 2 2: Add v = 2 to bottom i = 2 elements of the stack,  S = [6, 8,
1]. 
10. push 4: Push 4 onto the stack, S = [6, 8, 1, 4]. 
11. pop: Pop the top element from the stack, S = [6, 8, 1]. 
12. pop: Pop the top element from the stack, S = [6, 8].
 

10/10

You might also like