Untitled
unknown
plain_text
18 days ago
2.4 kB
8
Indexable
Never
//Q1. Suspicious Activity. //A list of strings in the format [{"AA BB NN"}, {.. .. ..}, ....] sperated by whitespace, AA is the sender, BB Receiver, NN is the amount. Threshold is the minimum //number of occurences. Return a sorted list of sender/receiver with of occurences above threshold. //My attempt with multiple TLE and WA (I was in a rush :')--- static List<string> processLogs(List<string> logs, int threshold) { List<string> sus = new(); Dictionary<int, int> dict = new(); foreach (var entry in logs) { string[] userList = entry.Split(" "); if(!dict.ContainsKey(Int32.Parse(userList[0]))) dict.Add(Int32.Parse(userList[0]), 1); else dict[Int32.Parse(userList[0])]++; if(userList[0] == userList[1]) continue; if(!dict.ContainsKey(Int32.Parse(userList[1]))) dict.Add(Int32.Parse(userList[1]), 1); else dict[Int32.Parse(userList[1])]++; } foreach (KeyValuePair<int,int> kvp in dict) { if(kvp.Value >= threshold) sus.Add(kvp.Key.ToString()); } sus.Sort(); return sus; } //Q2. Find Minimum Weight //A list of integers w = {} denote the weights of chocolates. And an integer N for how many days they can be eaten. Each day only one chocolate can be eaten and half of //it's weight will remain. One chocolate can be eaten multiple times. Find the minimum total weight of the chocolates //a rough example w = {30, 20, 15}, N = 4 // Day Weights After Eating // // 1 30, 20, 15 15, 20, 15 // 2 15, 20, 15 15, 10, 15 // 3 .......... .......... // 4 .......... .......... //My attempt--- public static int findMinWeight(List<int> weights, int d) { int currentMinTotal = Int32.MaxValue; List<int> nw = weights.ToList(); for (int i = 0; i < d; i++) { var total = 0; foreach (var weight in nw) { total += weight; } var currentMin = total; for (int j = 0; j < nw.Count; j++) { if (currentMin < (total - (nw[j] / 2))) { currentMin = total - (nw[j] / 2); nw[j] = (nw[j] / 2) + 1; } } if (currentMinTotal > currentMin) currentMinTotal = currentMin; } return currentMinTotal; }
Leave a Comment