-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwitter-Karthik-tokenmap
More file actions
55 lines (47 loc) · 1.56 KB
/
Copy pathTwitter-Karthik-tokenmap
File metadata and controls
55 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
public class Solution {
static TreeMap<Integer,Integer> map=new TreeMap<>(); //contains id:expiry time
static int current_time=0;
public static int numberOfTokens(int expiryLimit, List<List<Integer>> commands) {
// Write your code here
for(List<Integer> command:commands){
int type=command.get(0);
int id=command.get(1);
int time=command.get(2);
current_time=time;
//reset logic
if(type==1){
if(map.containsKey(id)){
//check if alive or not
if(current_time>map.get(id))
continue;
}else{
continue;
}
}
//get or if reset the token
map.put(id,time+expiryLimit);
System.out.println(map);
}
System.out.println(current_time);
return aliveTokenCount();
}
private static int aliveTokenCount() {
int count=0;
for(int time:map.values()){
count+=(time>=current_time)?1:0;
}
return count;
}
public static void main(String args[]) {
int exp=3;
List<List<Integer>> list=new ArrayList<>();
List<Integer> sublist;
sublist=new ArrayList<>(Arrays.asList(0,1,1));
list.add(sublist);
sublist=new ArrayList<>(Arrays.asList(1,1,4));
list.add(sublist);
sublist=new ArrayList<>(Arrays.asList(1,2,5));
list.add(sublist);
System.out.println(numberOfTokens(exp,list));
}
}