Packets are sent to different ports on a computer system based on the hash of their packet ID. The value of the hash is as given below:
Hash = mod (packet_id, numberOfPorts)
where mod is the modulus operator and takes the mod of first operand by second operand.
The ports are numbered from 0 to (number of ports)-1, and a packet is initially sent to the port that has the post number equal to the hash of its packet ID. Each port requires a time t to send a packet. If a port is currently sending a packet, this packet is then sent to the next port number, and so on. Given that x packets arrive 3 per second, and given the IDs of the packets, find the port at which each packet is finally sent First packet as sent at time t=1.
Complete the sentTimes function in the editor below. The function must return an integer array denoting the ports at which the packets are sent.
sentTimes has the following parameter(s):
numberOfPorts: An integer, the number of ports in the system.
transmissionTime: An integer, tha time for a port to send a packet
packetIds: An integer array, where packetIds, describes the IDs of the packets in the order in which they arrive.
1 <= numberOfPorts <= 2000
1 <= transmissionTime <= 100
1 <= x <= 2000
1 <= packetIds <= 10^5