Problem · Simulation

Get Minimum Time for DNS Resolution (for Data Science Developer)

Learn this problem
EasyIBMFULLTIMEOA
See IBM hiring insights

Problem statement

A Domain Name System (DNS) translates domain names to IP addresses which are then used by browsers to load internet resources. For quicker DNS lookups, browsers store a number of recent DNS queries in a DNS cache. Retrieving data from the cache is often faster than retrieving it from a DNS server. This task aims to simulate DNS resolution and determine the time taken to process different URLs.

Assume that each DNS cache can store a maximum of the cache_size most recent DNS requests, i.e., URL-IP mappings. The cache is initially empty. It takes cache_time units of time to fetch data from the DNS cache, and server_time units of time to fetch data from the DNS server.

Given a list of URLs visited as an array of strings, urls, determine the minimum time taken to resolve each DNS request.

Note: New DNS requests are dynamically added to the cache, and the cache stores mappings according to the order in which the requests were made.

Function

getMinTime(cache_size: int, cache_time: int, server_time: int, urls: String[]) → int[]

Complete the function getMinTime in the editor.

getMinTime has the following parameters(s):

  1. int cache_size: the size of the DNS cache
  2. int cache_time: the time taken to fetch data from the cache
  3. int server _time: the time taken to resolve an address using the DNS server
  4. String urls[n]: the URLs visited by a user

Returns

int[n]: the minimum time to resolve each DNS request

📢 Important announcement - all credit goes to da best 🥑 spike 🥝!!! 🫶

Examples

Example 1

cache_size = 2cache_time = 2server_time = 3urls = ["www.google.com", "www.yahoo.com",  "www.google.com", "www.yahoo.com", "www.coursera.com"]return = [3, 3, 2, 2, 3]
:)

Example 2

cache_size = 3cache_time = 2server_time = 5urls = ["http://www.hackerrank.com", "http://www.google.com", "http://www.gmail.com", "http://www.yahoo.com", "http://www.hackerrank.com","http://www.gmail.com"]return = [5, 5, 5, 5, 5, 2]
:P

Constraints

  • 1 ≤ n ≤ 10^5
  • 1 ≤ cache_size ≤ 10^5
  • 1 ≤ cache_time, server_time ≤ 10^9
  • 1 ≤ size of urls[i] ≤ 20

More IBM problems

drafts saved locally
public int[] getMinTime(int cache_size, int cache_time, int server_time, String[] urls) {
  // write your code here
}
cache_size2
cache_time2
server_time3
urls["www.google.com", "www.yahoo.com", "www.google.com", "www.yahoo.com", "www.coursera.com"]
expected[3, 3, 2, 2, 3]
checking account