GTS Quant Coding Test . You have been invited to attend the challenge GTS Quant Coding Test. We wish you all the best!

今天石老师给大家带来了GTS qunt 岗位的OA笔试题,如果有刷题的同学一定要收藏备用哦。

Question 18

Implement a Least Frequently Used (LFU) cache data structure of size n that handles two types of queries, GET and PUT.

  • A GET query attempts to retrieve the value of a given key.
    • If the key is present in the cache, it is returned.
    • Otherwise, it returns -1.
  • A PUT query updates or inserts a key-value pair into the cache.
    • When the cache is full, the least frequently used key is removed to accommodate the new key-value pair.
    • If there is a tie in the frequency of keys, then the least recently used key is removed.

Return an array of integers where each iᵗʰ element is the answer for the iᵗʰ GET query.

Example
Suppose cacheSize = 1, q = 5, queries = ["PUT 1 1", "PUT 2 2", "GET 1"]
Only cacheSize = 1 element is stored in the cache.

Query No.Query TypeKeyValueCache StateOutput
1PUT111:1
2PUT222:2
3GET12:2-1

Hence the answer is [-1].

Function Description
Complete the function implementLFU in the editor below
implementLFU has the following parameters:

  • int cacheSize: the size of the cache
  • string queries[q]: the query strings

Returns

  • int[]: the answers to the GET queries

Question 20

Chris and Alex are in a game show where they navigate a maze with hidden gold coins. Chris must collect all gold coins and deliver them to Alex’s location. Chris can move horizontally or vertically within the maze through unblocked cells.

  • The maze is represented as an n × m grid
  • Each cell can be one of three values:
    • 0: Open cell
    • 1: Blocked cell
    • 2: Open cell with a gold coin
  • Chris starts at position (0, 0)
  • Alex is at a specified position (x, y)

Return the length of the shortest path for Chris to collect all gold coins and reach Alex. If it is not possible to collect all coins and reach Alex, return -1.


Example

maze = [[0,2,1],
        [2,0,1],
        [0,1,0]]
Alex at (2,2)

Chris starts at position (0,0)
Alex is at position (2,2)
Gold coins are at positions (0,1) and (1,0)

The shortest possible path length is 4, which can be achieved by:

  • Path 1: (0,0) → (0,1) → (1,1) → (1,0) → (2,2)
  • Path 2: (0,0) → (0,1) → (1,1) → (1,0) → (2,0) → (2,2)

Function Description
Complete the function minMoves in the editor with the following parameters:

int maze[n][m]: a 2D array of integers  
int x: Alex’s row coordinate  
int y: Alex’s column coordinate  

Returns
int: length of Chris’s shortest path, or -1 if it is not possible


Constraints

  • 1 ≤ n, m ≤ 100
  • 0 ≤ the number of coins ≤ 10
  • 1 ≤ x ≤ n
  • 1 ≤ y ≤ m

我们长期稳定承接各大科技公司如Visa、TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *