question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
the-number-of-full-rounds-you-have-played
C++ || the-number-of-full-rounds-you-have-played
c-the-number-of-full-rounds-you-have-pla-t0iz
\nclass Solution {\npublic:\n int solve(string s)\n {\n int hour=stoi(s.substr(0,2));\n int min=stoi(s.substr(3,5));\n return hour*60
hansikarastogi99
NORMAL
2022-01-21T13:12:00.971102+00:00
2022-01-21T13:35:44.524667+00:00
217
false
```\nclass Solution {\npublic:\n int solve(string s)\n {\n int hour=stoi(s.substr(0,2));\n int min=stoi(s.substr(3,5));\n return hour*60+min;\n }\n int numberOfRounds(string loginTime, string logoutTime) {\n int st=solve(loginTime);\n int et=solve(logoutTime);\n int ans=0;\n if(st>et) et=et+1440;\n if(st%15!=0) st=st+(15-st%15);\n ans=(et-st)/15;\n return ans;\n }\n};\n```\n
1
0
['C', 'C++']
0
the-number-of-full-rounds-you-have-played
C++ || 100% FAST || SIMULATION
c-100-fast-simulation-by-easy_coder-ed6j
```\nclass Solution {\npublic:\n int numberOfRounds(string loginTime, string logoutTime) {\n string liHr = loginTime.substr(0,2);\n string lg
Easy_coder
NORMAL
2021-12-30T06:39:31.051562+00:00
2021-12-30T06:39:31.051601+00:00
148
false
```\nclass Solution {\npublic:\n int numberOfRounds(string loginTime, string logoutTime) {\n string liHr = loginTime.substr(0,2);\n string lgHr = logoutTime.substr(0,2);\n \n string liMt = loginTime.substr(3,4);\n string lgMt = logoutTime.substr(3,4);\n \n int total_logInTime = stoi(liHr) * 60 + stoi(liMt);\n int total_logOutTime = 0;\n \n if(liHr > lgHr || (liHr==lgHr && liMt>lgMt)){\n total_logOutTime = 24;\n }\n \n total_logOutTime = (total_logOutTime + stoi(lgHr)) * 60 + stoi(lgMt);\n \n if(total_logInTime % 15 != 0){\n total_logInTime += 15 - (total_logInTime % 15);\n }\n \n int ans = 0;\n \n for(int i=total_logInTime ; i<=total_logOutTime; i+=15){\n if(i+15 <= total_logOutTime)\n ans++; \n }\n \n return ans;\n \n }\n};
1
0
['C', 'Simulation']
0
the-number-of-full-rounds-you-have-played
Simple C++: Straight forward math solution || 0 ms Faster than 100% ||Short code
simple-c-straight-forward-math-solution-4ijoy
\nclass Solution {\npublic:\n int numberOfRounds(string login, string logout) {\n int h1,m1,h2,m2;\n string s="";\n s=login.substr(0,2);\
akcse
NORMAL
2021-12-28T18:43:18.956782+00:00
2021-12-29T09:30:52.922769+00:00
175
false
```\nclass Solution {\npublic:\n int numberOfRounds(string login, string logout) {\n int h1,m1,h2,m2;\n string s="";\n s=login.substr(0,2);\n h1=stoi(s);\n s=login.substr(3,2);\n m1=stoi(s);\n s=logout.substr(0,2);\n h2=stoi(s);\n s=logout.substr(3,2);\n m2=stoi(s);\n int x1=m1,x2=m2;///storing original minutes in var\n if(m1%15!=0)\n {\n int p=m1/15;\n p++;\n m1=p*15;\n }\n if(m2%15!=0)\n {\n int p=m2/15;\n m2=p*15;\n }\n if(h1==h2 && x1<x2) // special case if hour are equal \n {\n if(m2-m1<0)\n return 0;\n else\n return (m2-m1)/15;\n }\n int sum1=h1*60+m1;\n int sum2=h2*60+m2;\n // cout<<sum1<<" "<<sum2;\n if(sum1<=sum2)\n {\n return (sum2-sum1)/15;\n }\n else\n {\n sum1=1440-sum1;\n return(sum1+sum2)/15;\n }\n \n }\n};\n```
1
0
['C', 'C++']
0
the-number-of-full-rounds-you-have-played
python 3 solution
python-3-solution-by-sadman022-r5ia
\ndef numberOfRounds(self, startTime: str, finishTime: str) -> int:\n\tstartTime = int(startTime[:2])*60+int(startTime[3:])\n\tfinishTime = int(finishTime[:2])*
sadman022
NORMAL
2021-10-31T12:29:31.410581+00:00
2021-10-31T12:29:31.410612+00:00
272
false
```\ndef numberOfRounds(self, startTime: str, finishTime: str) -> int:\n\tstartTime = int(startTime[:2])*60+int(startTime[3:])\n\tfinishTime = int(finishTime[:2])*60+int(finishTime[3:])\n\n\tstart, finish = math.ceil(startTime/15)*15, math.floor(finishTime/15)*15\n\n\tif finishTime>=startTime:\n\t\tplayed = (finish-start)//15\n\t\treturn max(0, played)\n\treturn (1440-start+finish)//15\n```
1
0
['Python3']
0
the-number-of-full-rounds-you-have-played
Java Solution
java-solution-by-arunindian10-rz1w
\tclass Solution {\n public int numberOfRounds(String startTime, String finishTime) \n {\n String[] start = startTime.split(":");\n String[]
arunindian10
NORMAL
2021-10-17T09:22:26.778535+00:00
2021-10-17T09:22:26.778569+00:00
162
false
\tclass Solution {\n public int numberOfRounds(String startTime, String finishTime) \n {\n String[] start = startTime.split(":");\n String[] end = finishTime.split(":");\n \n int startHour = Integer.parseInt(start[0]);\n int startMinute = Integer.parseInt(start[1]);\n int endHour = Integer.parseInt(end[0]);\n int endMinute = Integer.parseInt(end[1]);\n \n int totalRounds = 0;\n int hourDiff = 0;\n if(startHour > endHour)\n {\n hourDiff = (24-startHour) + endHour;\n }\n else if(endHour > startHour)\n {\n hourDiff = endHour - startHour;\n }\n else if(startMinute > endMinute)\n {\n hourDiff = 24;\n }\n else\n {\n hourDiff = 0;\n }\n \n if(hourDiff >= 1)\n {\n totalRounds += (hourDiff-1)*4;\n if(startMinute == 0)\n {\n totalRounds += 4;\n }\n else if(startMinute <= 15)\n {\n totalRounds += 3;\n }\n else if(startMinute <= 30)\n {\n totalRounds += 2;\n }\n else if(startMinute <= 45)\n {\n totalRounds += 1;\n }\n \n if(endMinute >= 45)\n {\n totalRounds += 3;\n }\n else if(endMinute >= 30)\n {\n totalRounds += 2;\n }\n else if(endMinute >= 15)\n {\n totalRounds += 1;\n }\n }\n else\n {\n if(startMinute == 0 && endMinute >= 15)\n {\n totalRounds += 1;\n }\n \n if(startMinute <= 15 && endMinute >= 30)\n {\n totalRounds += 1;\n }\n \n if(startMinute <= 30 && endMinute >= 45)\n {\n totalRounds += 1;\n }\n }\n \n return totalRounds;\n }\n\t}
1
1
[]
0
the-number-of-full-rounds-you-have-played
[JAVA] Easy, Clean and Detailed Solution
java-easy-clean-and-detailed-solution-by-cnrl
\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n String[] t1 = startTime.split(":");\n int h1 = Integer.
Dyanjno123
NORMAL
2021-09-18T06:35:25.261018+00:00
2021-09-18T06:35:25.261046+00:00
267
false
```\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n String[] t1 = startTime.split(":");\n int h1 = Integer.parseInt(t1[0]);\n int m1 = Integer.parseInt(t1[1]);\n \n t1 = finishTime.split(":");\n int h2 = Integer.parseInt(t1[0]);\n int m2 = Integer.parseInt(t1[1]);\n \n if(h1 == h2 && m2 - m1 < 15 && m2 - m1 >= 0)\n return 0;\n if(m1 > 0 && m1 <= 14)\n \tm1 = 15;\n else if(m1 > 15 && m1 < 30)\n \tm1 = 30;\n else if(m1 > 30 && m1 < 45)\n \tm1 = 45;\n else if(m1 > 45 && m1 <= 59) {\n \tm1 = 0;\n \th1++;\n }\n \n if(m2 > 0 && m2 <= 14)\n \tm2 = 0;\n else if(m2 > 15 && m2 < 30)\n \tm2 = 15;\n else if(m2 > 30 && m2 < 45)\n \tm2 = 30;\n else if(m2 > 45 && m2 <= 59) {\n \tm2 = 45;\n }\n \n int x = h1 * 60 + m1;\n int y = h2 * 60 + m2;\n \n if(y >= x)\n \treturn (y - x) / 15;\n else\n \treturn (((24 * 60) - x) + y) / 15;\n }\n}\n```
1
1
['Java']
0
the-number-of-full-rounds-you-have-played
0ms runtime C++ solution
0ms-runtime-c-solution-by-karandua-tlil
```\n\nclass Solution {\npublic:\n int numberOfRounds(string s, string f) {\n string h = "", m = "", h1 = "", m1 = "";\n int j, count = 0;\n
KaranDua
NORMAL
2021-08-19T18:01:24.783087+00:00
2021-09-10T13:16:37.056006+00:00
166
false
```\n\nclass Solution {\npublic:\n int numberOfRounds(string s, string f) {\n string h = "", m = "", h1 = "", m1 = "";\n int j, count = 0;\n for(int i = 0; i<s.length(); i++){\n if(s[i]==\':\'){j = i;break;}\n h+=s[i];\n }\n for(int i = j+1; i<s.length(); i++){\n m+=s[i];\n }\n for(int i = 0; i<f.length(); i++){\n if(f[i]==\':\'){j = i;break;}\n h1+=f[i];\n }\n for(int i = j+1; i<f.length(); i++){\n m1+=f[i];\n }\n string d = "00";\n if(!m.compare(d)&&!m1.compare(d)){\n int l = stoi(h);\n int e = stoi(h1);\n if(e<l){\n e+=24;\n return(4*(e-l));\n }else{return(4*(e-l));}\n }if(m.compare(d)!=0){\n int l = 60 - stoi(m);\n int e = l/15;\n count+=e;\n if(m1.compare(d)!=0){\n int z = stoi(m1)-0;\n count+=(z/15);\n int n = stoi(h);\n int o = stoi(h1);\n if(o<n){\n o+=24;\n count+=4*(o-1 - (n));\n }else if(o==n){\n if(stoi(m1)<stoi(m)){\n o+=24;\n count+=4*(o-1 - (n));\n }else{\n if(stoi(m1)%15==0||stoi(m)%15==0){\n count = (stoi(m1) - stoi(m))/15;\n }\n else{\n if(stoi(m1) - stoi(m)<15){count=0;}\n else{\n int y = stoi(m);\n while(y%15!=0){y++;}\n count = (stoi(m1) - y)/15;\n }\n \n }\n \n }\n \n }\n else{\n count+=4*(o-1 - (n));\n }\n }else{\n int n = stoi(h);\n int o = stoi(h1);\n if(o<n){\n o+=24;\n count+=4*(o-1 - (n));\n }else if(o==n){\n if(stoi(m1)<stoi(m)){\n o+=24;\n count+=4*(o-1 - (n));\n }else{\n count+=4*(o-1 - (n)); \n }\n \n }\n else{\n count+=4*(o-1-(n));\n }\n }\n }\n else if(m1.compare(d)!=0){\n int l = stoi(m1)-0;\n int e = l/15;\n count+=e;\n if(m.compare(d)!=0){\n int z = stoi(m)-0;\n count+=(z/15);\n int n = stoi(h);\n int o = stoi(h1);\n if(o<n){\n o+=24;\n count+=4*(o-1 - (n));\n }else if(o==n){\n if(stoi(m1)<stoi(m)){\n o+=24;\n count+=4*(o-1 - (n));\n }else{\n count+=4*(o-1 - (n)); \n }\n \n }\n else{\n count+=4*(o-1 - n);\n }\n }else{\n int n = stoi(h);\n int o = stoi(h1);\n if(o<n){\n o+=24;\n count+=4*(o - (n));\n }else if(o==n){\n if(stoi(m1)<stoi(m)){\n o+=24;\n count+=4*(o - (n));\n }else{\n \n count+=4*(o - (n)); \n }\n \n }else{\n \n count+=4*(o - (n));\n }\n }\n }\n return count;\n }\n};
1
0
[]
0
the-number-of-full-rounds-you-have-played
C++ straightforward
c-straightforward-by-eplistical-1jir
For a given time point h:m, we can calculate the number of full round between 00:00 to h:m easily, which is N(h, m) = h * 4 + m / 15.\nNow let startTime be h0:m
eplistical
NORMAL
2021-08-11T23:23:28.663453+00:00
2021-08-11T23:23:28.663492+00:00
162
false
For a given time point `h:m`, we can calculate the number of full round between `00:00` to `h:m` easily, which is `N(h, m) = h * 4 + m / 15`.\nNow let `startTime` be `h0:m0` and finishTime be `h1:m1`, we calculate their difference `N(h1,m1) - N(h0,m0)`. Furthermore, if `m0 % 15 != 0`, we should remove 1 round, as the player does not fully play the first round.\nThere are two edge cases:\n1. when `h1:m1 < h0:m0`, the player is playing overnight, we can just replace `h1` with `h1 + 24`.\n2. when `N(h1,m1) - N(h0,m0) == 0`, in this case we should not remove the first round whne `m0 % 15 != 0` as `-1` will not be a valid answer. In this case we just return `0`.\n\n```\nclass Solution {\npublic:\n int fullRoundBefore(int h, int m) {\n return h * 4 + m / 15; \n }\n \n int numberOfRounds(string startTime, string finishTime) {\n\t\t// Time O(1), Space O(1)\n int h0 = stoi(startTime.substr(0,2));\n int m0 = stoi(startTime.substr(3,2));\n int h1 = stoi(finishTime.substr(0,2));\n int m1 = stoi(finishTime.substr(3,2));\n if (h1 < h0 or (h1 == h0 and m1 < m0)) {\n h1 += 24;\n }\n return max(0, fullRoundBefore(h1, m1) - fullRoundBefore(h0, m0) - (m0 % 15 != 0));\n }\n};\n```
1
0
['C++']
0
the-number-of-full-rounds-you-have-played
[C++] calculate round for start and finish time respectively.
c-calculate-round-for-start-and-finish-t-2zgs
\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n int startHour, startMin, stopHour, stopMin;\n \n
lovebaonvwu
NORMAL
2021-07-23T07:39:26.256671+00:00
2021-07-23T07:39:26.256714+00:00
92
false
```\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n int startHour, startMin, stopHour, stopMin;\n \n startHour = stoi(startTime.substr(0, 2));\n startMin = stoi(startTime.substr(3, 2));\n stopHour = stoi(finishTime.substr(0, 2));\n stopMin = stoi(finishTime.substr(3, 2));\n \n int start = startHour * 60 + startMin;\n int stop = stopHour * 60 + stopMin;\n \n if (start > stop) {\n stop += 24 * 60;\n }\n \n start = (start / 15) + (start % 15 > 0);\n stop /= 15;\n \n return max(stop - start, 0);\n }\n};\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
simple java code
simple-java-code-by-ly2015cntj-83y5
java\n// AC: Runtime: 1 ms, faster than 63.13% of Java online submissions for The Number of Full Rounds You Have Played.\n// Memory Usage: 37.2 MB, less than 74
ly2015cntj
NORMAL
2021-07-23T03:45:16.249982+00:00
2021-07-23T03:45:16.250017+00:00
279
false
```java\n// AC: Runtime: 1 ms, faster than 63.13% of Java online submissions for The Number of Full Rounds You Have Played.\n// Memory Usage: 37.2 MB, less than 74.19% of Java online submissions for The Number of Full Rounds You Have Played.\n// .\n// T:O(len(startTime) + len(finishTime)), S:O(1)\n//\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n String[] arr1 = startTime.split(":"), arr2 = finishTime.split(":");\n int hour1 = Integer.parseInt(arr1[0]), minute1 = Integer.parseInt(arr1[1]), hour2 = Integer.parseInt(arr2[0]), minute2 = Integer.parseInt(arr2[1]);\n if (hour1 > hour2 || (hour1 == hour2 && minute1 > minute2)) {\n hour2 += 24;\n }\n int ret = 0;\n // gap at least one hour\n if (hour2 - hour1 >= 1) {\n ret += (hour2 - hour1 - 1) * 4;\n ret += (60 - minute1) / 15 + minute2 / 15;\n }\n // in same hour, compare minute.\n // notice if minute2 % 15 != 0 and ret > 0, will cause one quarter invalid.\n else {\n ret += (60 - minute1) / 15 - (60 - minute2) / 15;\n if (ret > 0 && minute2 % 15 != 0) {\n ret -= 1;\n }\n }\n\n return ret;\n }\n}\n```
1
0
['Java']
0
the-number-of-full-rounds-you-have-played
Swift: The Number of Full Rounds You Have Played (+ Test Cases)
swift-the-number-of-full-rounds-you-have-izkq
swift\nclass Solution {\n private func timeStr2Int(_ time: String) -> Int {\n let split = time.split(separator: ":")\n return (Int(split[0]) ??
AsahiOcean
NORMAL
2021-07-04T16:29:56.101752+00:00
2021-07-04T16:29:56.101796+00:00
179
false
```swift\nclass Solution {\n private func timeStr2Int(_ time: String) -> Int {\n let split = time.split(separator: ":")\n return (Int(split[0]) ?? 0) * 60 + (Int(split[1]) ?? 0)\n }\n func numberOfRounds(_ startTime: String, _ finishTime: String) -> Int {\n var s = timeStr2Int(startTime), f = timeStr2Int(finishTime)\n if f < s { f += 24 * 60 }\n var result = 0\n for t in s...f where t % 15 == 0 && f-t >= 15 { result += 1 }\n return result\n }\n}\n```\n\n```swift\nimport XCTest\n\n// Executed 3 tests, with 0 failures (0 unexpected) in 0.034 (0.036) seconds\n\nclass Tests: XCTestCase {\n private let s = Solution()\n func test1() {\n let result = s.numberOfRounds("12:01", "12:44")\n XCTAssertEqual(result, 1)\n }\n func test2() {\n let result = s.numberOfRounds("20:00", "06:00")\n XCTAssertEqual(result, 40)\n }\n func test3() {\n let result = s.numberOfRounds("00:00", "23:59")\n XCTAssertEqual(result, 95)\n }\n}\n\nTests.defaultTestSuite.run()\n```
1
0
['Swift']
0
the-number-of-full-rounds-you-have-played
C++: simple O(1) time O(1) space solution
c-simple-o1-time-o1-space-solution-by-us-ew8l
```\nclass Solution {\npublic:\n /// 0 ms, faster than 100.00% of C++\n /// 6 MB, less than 11.60% of C++\n int numberOfRounds(string st, string ft)\n
user1378k
NORMAL
2021-07-02T18:58:04.458681+00:00
2021-07-02T18:58:04.458724+00:00
124
false
```\nclass Solution {\npublic:\n /// 0 ms, faster than 100.00% of C++\n /// 6 MB, less than 11.60% of C++\n int numberOfRounds(string st, string ft)\n {\n\t /// both start and finish will be = hours * 60 + minutes\n int start = ((st[0]-\'0\')*10 + (st[1]-\'0\')) * 60 + ((st[3]-\'0\')*10 + (st[4]-\'0\'));\n int finish = ((ft[0]-\'0\')*10 + (ft[1]-\'0\')) * 60 + ((ft[3]-\'0\')*10 + (ft[4]-\'0\'));\n\t\t/// if finish is earlier than the start => add a full day\n if (finish < start)\n finish += 24*60;\n\t\t/// make sure that we use 15-minute intervals\n if (start % 15)\n start += 15 - (start % 15);\n if (finish % 15)\n finish -= (start % 15);\n return (finish - start) / 15;\n }\n};
1
0
[]
0
the-number-of-full-rounds-you-have-played
C++ - O(1) Solution
c-o1-solution-by-swapnil007-qcvn
\nclass Solution {\npublic:\n int numberOfRounds(string s, string f) {\n int S = stoi(s.substr(0,2))*60 + stoi(s.substr(3));\n int F = stoi(f.s
swapnil007
NORMAL
2021-06-29T08:50:51.082653+00:00
2021-06-29T08:50:51.082693+00:00
107
false
```\nclass Solution {\npublic:\n int numberOfRounds(string s, string f) {\n int S = stoi(s.substr(0,2))*60 + stoi(s.substr(3));\n int F = stoi(f.substr(0,2))*60 + stoi(f.substr(3));\n \n if(S<F && F-S<15)\n {\n return 0;\n }\n \n S = 15*((S+14)/15);\n F = 15*(F/15);\n \n int H;\n if(S>F)\n {\n H=24*60 - S + F;\n }\n else\n {\n H=F-S;\n }\n return H/15;\n }\n};\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
Java - 100% time 97% space
java-100-time-97-space-by-ricka21-n6t0
\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n byte start_hour = Byte.parseByte(startTime.substring(0,2));\n
rickA21
NORMAL
2021-06-27T12:59:44.985811+00:00
2021-06-27T12:59:44.985839+00:00
107
false
```\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n byte start_hour = Byte.parseByte(startTime.substring(0,2));\n byte start_min = Byte.parseByte(startTime.substring(3,5));\n byte end_hour = Byte.parseByte(finishTime.substring(0,2));\n byte end_min = Byte.parseByte(finishTime.substring(3,5));\n \n byte value = (byte)(end_hour*4 + end_min/15 - start_hour*4 - (start_min+14)/15);\n if (start_hour>end_hour || (start_hour==end_hour && start_min>end_min)){\n value+=96;\n }\n \n return value<0?0:value;\n }\n}\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
My easy and intuitive solution
my-easy-and-intuitive-solution-by-legit_-at9j
This was what I came up with , its pretty straightforward and I think its an O(1) time and space solution , now hear me out , I have used substring function whi
legit_123
NORMAL
2021-06-23T15:40:48.063931+00:00
2021-06-23T15:40:48.063959+00:00
119
false
This was what I came up with , its pretty straightforward and I think its an O(1) time and space solution , now hear me out , I have used substring function which takes linear time , and also used loops for looping from start time to finish time , but I would still call it constant time and space because the length of input string is constant , its just time in hours and minutes , so my substring function becomes constant time , and in my loop , it runs at maximum for 24 hours , which is also constant , so overall O(1) time and space\n\nI have looked at other solutions but I have a hard time understanding how they work and I think this solution is good enough \n\nHere is my code , if you have any doubts then do comment down below and I will help you out , oh and by the way dont forget to dislike this question because it SUCKS\n\n```\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n int si1 = -1; // position of ":" in start\n int si2 = -1; // position of ":" in finish\n for(int i =0;i<startTime.length();i++){\n if(startTime.charAt(i)==\':\'){\n si1 = i;\n break;\n }\n }\n for(int i =0;i<finishTime.length();i++){\n if(finishTime.charAt(i)==\':\'){\n si2 = i;\n break;\n }\n }\n // split given time zones into hours and minutes\n int h1 = Integer.parseInt(startTime.substring(0,si1));\n int m1 = Integer.parseInt(startTime.substring(si1+1));\n int h2 = Integer.parseInt(finishTime.substring(0,si2));\n int m2 = Integer.parseInt(finishTime.substring(si2+1));\n int count = 0;\n if(h2<h1||(h2==h1&&m2<m1)) h2+=24; // this is the case when \n // you play overnight so you add 24 hours\n for(int i = h1;i<=h2;i++){\n int startM = (i==h1?m1:0); // if its the first hour\n // then you start from given minute otherwise \n // you start from the very start of the hour\n int endM = (i==h2?m2:59); // if its the last hour\n // then you end at given minute otherwise\n // you end at the very end of the hour\n for(int j = startM;j<=endM;j++){\n if(j==0||j==15||j==30||j==45){ // timestamps when you start the game\n if(j+15<=endM||(j==45&&(i<h2))) count++;\n // for j = 0,15,30 , you need to check\n // if after finishing the game your \n // time is less than end minute \n // and for j = 45 you need to check if \n // there is still one more hour left \n // for you to finish your game \n }\n }\n }\n return count;\n }\n}\n```\n
1
2
['Java']
0
the-number-of-full-rounds-you-have-played
Java simple solution
java-simple-solution-by-zmengsho-0jrb
\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n int start = convert2Min(startTime);\n int finish = conv
zmengsho
NORMAL
2021-06-22T23:41:27.127853+00:00
2021-06-22T23:41:27.127885+00:00
80
false
```\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n int start = convert2Min(startTime);\n int finish = convert2Min(finishTime);\n if(finish > start && finish - start < 15){\n return 0;\n }\n \n start = (start + 14) / 15 * 15;\n finish = finish / 15 * 15;\n \n int diff = finish - start;\n diff = (diff < 0) ? diff + 24 * 60 : diff;\n return diff / 15;\n }\n \n private int convert2Min(String time){\n String[] t = time.split(":");\n return Integer.parseInt(t[0]) * 60 + Integer.parseInt(t[1]);\n }\n}\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
Swift solution
swift-solution-by-yamironov-g3ol
Swift solution\n\nclass Solution {\n func time2Int(_ time: String) -> Int {\n let split = time.split(separator: ":")\n return (Int(split[0]) ??
yamironov
NORMAL
2021-06-22T13:35:37.607287+00:00
2021-06-22T13:35:37.607317+00:00
70
false
Swift solution\n```\nclass Solution {\n func time2Int(_ time: String) -> Int {\n let split = time.split(separator: ":")\n return (Int(split[0]) ?? 0) * 60 + (Int(split[1]) ?? 0)\n }\n func numberOfRounds(_ startTime: String, _ finishTime: String) -> Int {\n let roundTime = 15, startTime = time2Int(startTime), tpmTime = time2Int(finishTime), finishTime = tpmTime > startTime ? tpmTime : (tpmTime + time2Int("24:00"))\n var result = 0\n for roundStartTime in stride(from: 0, to: 2 * 24 * 60, by: roundTime) where startTime <= roundStartTime && finishTime >= (roundStartTime + roundTime) {\n result += 1\n }\n return result\n }\n}\n```
1
0
['Swift']
0
the-number-of-full-rounds-you-have-played
C++ Simple Brute Approach | 100% Time
c-simple-brute-approach-100-time-by-thea-oyr1
\nclass Solution {\npublic:\n int numberOfRounds(string st, string fi) {\n int h1=0, m1=0, h2=0, m2=0, ans=0;\n\t\t//Extracting the hour and minute in
theabhishek_g
NORMAL
2021-06-21T00:46:36.014712+00:00
2021-06-24T23:40:20.482796+00:00
107
false
```\nclass Solution {\npublic:\n int numberOfRounds(string st, string fi) {\n int h1=0, m1=0, h2=0, m2=0, ans=0;\n\t\t//Extracting the hour and minute individually\n h1 = st[0]-\'0\';\n h1 = h1*10 + (st[1]-\'0\');\n m1 = st[3]-\'0\';\n m1 = m1*10 + (st[4]-\'0\');\n h2 = fi[0]-\'0\';\n h2 = h2*10 + (fi[1]-\'0\');\n m2 = fi[3]-\'0\';\n m2 = m2*10 + (fi[4]-\'0\');\n\t\t//If start time is arithmetically greater than end time, we need to adjust by adding 24 hours to end time\n\t\t//this would not affect the result - food for thought ;)\n if(h1>h2 || h1==h2 && m1>m2) h2+=24; \n\t\t//approximating m1 and m2 to the nearest 15th minute\n m1 += (m1%15==0 ? 0: 15-m1%15);\n m2 -= (m2%15==0 ? 0 : m2%15);\n\t\t//now that we have all the necessary information, we convert time (hours and minutes) to minutes (imagine a time system which only functions on minutes, agnostic of everything else)\n int time1 = h1*4 + m1/15, time2 = h2*4 + m2/15;\n return (time2-time1<0 ? 0 : time2-time1);\n }\n};\n```
1
1
['C']
1
the-number-of-full-rounds-you-have-played
C++ | Long but easy to understand
c-long-but-easy-to-understand-by-omnipha-ojxu
\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n int start_hh = stoi(startTime.substr(0,2));\n int sta
omniphantom
NORMAL
2021-06-20T19:52:44.672854+00:00
2021-06-20T19:52:44.672898+00:00
34
false
```\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n int start_hh = stoi(startTime.substr(0,2));\n int start_mm = stoi(startTime.substr(3,2));\n \n int end_hh = stoi(finishTime.substr(0,2));\n int end_mm = stoi(finishTime.substr(3,2));\n \n std::function<void(int,int)> roundIt = [&](int hh, int mm){\n if(1<=mm && mm<15){\n start_mm=15;\n }\n else if(15<mm && mm<30){\n start_mm=30;\n }\n else if(30<mm && mm<45){\n start_mm=45;\n }\n else if(45<mm && mm<=59){\n start_mm=00;\n if(start_hh==23){\n start_hh=0;\n }\n else{\n start_hh++;\n }\n }\n };\n \n std::function<void()> move = [&](){\n if(start_hh==23){\n if(start_mm==0){\n start_mm+=15;\n }\n else if(start_mm==15){\n start_mm+=15;\n }\n else if(start_mm==30){\n start_mm+=15;\n }\n else if(start_mm==45){\n start_mm=0;\n start_hh=0;\n }\n }\n else{\n if(start_mm==0){\n start_mm+=15;\n }\n else if(start_mm==15){\n start_mm+=15;\n }\n else if(start_mm==30){\n start_mm+=15;\n }\n else if(start_mm==45){\n start_mm=0;\n start_hh++;\n }\n }\n };\n \n int cnt = 0;\n \n if(start_hh<end_hh){\n roundIt(start_hh,start_mm);\n if(start_hh==end_hh){\n while((end_mm-start_mm)>=15){\n move();\n cnt++;\n }\n }\n else{\n while(start_hh<end_hh){\n move();\n cnt++;\n }\n while((end_mm-start_mm)>=15){\n move();\n cnt++;\n }\n }\n }\n else if(start_hh==end_hh && start_mm<end_mm){\n roundIt(start_hh,start_mm);\n if(start_mm>=end_mm)\n return 0;\n while((end_mm-start_mm)>=15){\n move();\n cnt++;\n }\n }\n else if(start_hh==end_hh && start_mm==end_mm){\n return 96;\n }\n else if(start_hh==end_hh && start_mm>end_mm){\n roundIt(start_hh,start_mm);\n while((start_hh!=0)||(start_mm!=0)){\n // cout<<start_hh<<" "<<start_mm<<endl;\n move();\n cnt++;\n }\n while(start_hh<end_hh){\n move();\n cnt++;\n }\n while((end_mm-start_mm)>=15){\n move();\n cnt++;\n }\n }\n else if(start_hh>end_hh){\n roundIt(start_hh,start_mm);\n while((start_hh!=0)||(start_mm!=0)){\n move();\n cnt++;\n }\n while(start_hh<end_hh){\n move();\n cnt++;\n }\n while((end_mm-start_mm)>=15){\n move();\n cnt++;\n }\n }\n \n return cnt;\n }\n};\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
C++ solution, 100% faster. 0ms
c-solution-100-faster-0ms-by-pranavkhair-nnuy
\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n string startHour = "";\n startHour.push_back(startTim
pranavkhairnar016
NORMAL
2021-06-20T14:46:41.747714+00:00
2021-06-20T14:46:41.747744+00:00
80
false
```\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n string startHour = "";\n startHour.push_back(startTime[0]);\n startHour.push_back(startTime[1]);\n int sh = stoi(startHour);\n string startMin = "";\n startMin.push_back(startTime[3]);\n startMin.push_back(startTime[4]);\n int sm = stoi(startMin);\n string EndHour = "";\n EndHour.push_back(finishTime[0]);\n EndHour.push_back(finishTime[1]);\n int eh = stoi(EndHour);\n string endMin = "";\n endMin.push_back(finishTime[3]);\n endMin.push_back(finishTime[4]);\n int em = stoi(endMin);\n \n int min;\n if(sm == 0) {\n min = 0;\n }\n else if(sm < 15) {\n min = 1;\n }\n else if(sm == 15) {\n min = 2;\n }\n else if(sm < 30) {\n min = 3;\n }\n else if(sm == 30) {\n min = 4;\n }\n else if(sm < 45) {\n min = 5;\n }\n else if(sm == 45) {\n min = 6;\n }\n else if(sm < 60) {\n min = 7;\n }\n int emin;\n if(em == 0) {\n emin = 0;\n }\n else if(em < 15) {\n emin = 1;\n }\n else if(em == 15) {\n emin = 2;\n }\n else if(em < 30) {\n emin = 3;\n }\n else if(em == 30) {\n emin = 4;\n }\n else if(em < 45) {\n emin = 5;\n }\n else if(em == 45) {\n emin = 6;\n }\n else if(em < 60) {\n emin = 7;\n }\n if(eh == sh) {\n if(em > sm) {\n emin--;\n return (emin-min)/2;\n }\n int ans = 4*23;\n ans += (8-min)/2;\n ans += emin/2;\n return ans;\n }\n if(eh > sh) {\n int ans=0;\n ans += 4*(eh-sh-1);\n ans += (8-min)/2;\n ans += emin/2;\n return ans;\n }\n int ans = 0;\n ans += (8-min)/2;\n ans += emin/2;\n ans += 4*(23-sh);\n ans += 4*(eh);\n return ans;\n \n }\n \n};\n```
1
1
['C']
0
the-number-of-full-rounds-you-have-played
Javascript simple 100% time 100% space
javascript-simple-100-time-100-space-by-cjet1
Approach:\nConvert everything to minute and run a loop from start time in minutes to finish time in minutes\nAdd 24*60 minutes if finish time is less than start
theesoteric
NORMAL
2021-06-20T13:48:24.980059+00:00
2021-06-20T13:50:21.421358+00:00
249
false
Approach:\nConvert everything to minute and run a loop from start time in minutes to finish time in minutes\nAdd 24*60 minutes if finish time is less than start time\nIncrement the answer(except for the first occurrance) by 1 whenever minute count is multiple of 15\n\n```\n/**\n * @param {string} startTime\n * @param {string} finishTime\n * @return {number}\n */\nvar numberOfRounds = function(startTime, finishTime) {\n\n let startH,startM,finishH,finishM,start=-1,ans=0,addition=0,startInMin,finishInMin;\n startH = parseInt(startTime.substring(0,2));\n startM = parseInt(startTime.substring(3));\n finishH = parseInt(finishTime.substring(0,2));\n finishM = parseInt(finishTime.substring(3));\n \n if(finishH<startH || (finishH===startH && finishM<startM)){//Add 24*60 minutes if finish time is less than start time\n addition = 24*60;\n }\n \n startInMin = startH*60+startM;\n finishInMin = finishH*60+finishM+addition;\n \n for(let i=startInMin;i<=finishInMin;i++){\n if(i%15===0){\n if(start===-1){\n start=1;\n }else{\n ans++;\n }\n }\n }\n return ans;\n};\n```
1
0
['JavaScript']
0
the-number-of-full-rounds-you-have-played
Python 100% time and 100% space
python-100-time-and-100-space-by-anantmu-913c
\nclass Solution:\n\n\tdef numberOfRounds(self, startTime: str, finishTime: str) -> int:\n\t\ts1=int(startTime[:2])\n s2=int(startTime[3:])\n e1=i
anantmundankar
NORMAL
2021-06-20T13:18:31.500738+00:00
2021-06-20T13:20:15.595830+00:00
235
false
`\nclass Solution:\n\n\tdef numberOfRounds(self, startTime: str, finishTime: str) -> int:\n\t\ts1=int(startTime[:2])\n s2=int(startTime[3:])\n e1=int(finishTime[:2])\n e2=int(finishTime[3:])\n sT=s1*60 + s2\n eT=e1*60 + e2\n if sT%15==0:\n pass\n else:\n sT+=15-sT%15\n if eT%15==0:\n pass\n else:\n eT-=eT%15\n if sT<=eT:\n return (abs(sT-eT)//15)\n else:\n return 96 - (abs(sT-eT)//15)\n`\n\n1) We calculate both the times with respect to "00:00"\n2) We adjust the values be be either starting or ending times\n3) We calculate the number of Sessions by diving the times by duration of sessions
1
0
['Python']
0
the-number-of-full-rounds-you-have-played
Java clean, easy to think of, very clear explanation
java-clean-easy-to-think-of-very-clear-e-rk4s
I am fresh here. Using the most stupid way to solve this problem. Include the special cases need to solve \n\nclass Solution {\n public int numberOfRounds(St
pliu23
NORMAL
2021-06-20T08:17:44.863421+00:00
2021-06-20T08:21:33.970295+00:00
59
false
I am fresh here. Using the most stupid way to solve this problem. Include the special cases need to solve \n```\nclass Solution {\n public int numberOfRounds(String start, String finish){\n \n //I am a fresh java user, do not know other ways to split the string\n \n // here we want sh = start hour, eh = end hour, sm = start min, em = end min\n String[] res = start.split(":");\n int sh = Integer.parseInt(res[0]);\n int sm = Integer.parseInt(res[1]);\n String[] res2 = finish.split(":");\n int eh = Integer.parseInt(res2[0]);\n int em = Integer.parseInt(res2[1]);\n \n //first we resolve the special case that he plays overnight, \n\t\t//that\'s the end hour is even bigger than the start hour, we plus 24\n if(eh < sh)\n eh = eh + 24;\n \n // the secpnd special case. The start and end hour is the same, but the minutes are different\n if(eh == sh){\n \n // the first sub case, end is smaller than the start min, \n\t\t\t//we add 24 to the end hour, becasue it is playing overnight\n if(em < sm)\n eh = eh + 24; \n else{\n \n //the second sub case, end is bigger than the start min\n\t\t\t\t//we find the time left in the start hour for him to play for the start time\n\t\t\t\t//and the time he could play if he only have the end time\n\t\t\t\t//add these two together and subtract 4 ( it means 60 / 15) \n\t\t\t\t//can we get exactlly how many runs can he play in this hour\n\t\t\t\t\n sm = (60 - sm) / 15;\n em = em / 15;\n return em + sm - 4;\n \n } \n }\n \n //for other cases, including the previous adding 24 hours cases, \n\t\t//we can consider the remaining time for him to play in the start hour\n\t\t//and the runs he can play in the end hour, and then \n\t\t//add the hours between the start and the end and subtract 1\n\t\t\n int run1 = (60 - sm) / 15;\n int run2 = em / 15;\n int run = (eh - sh - 1) * 4 + (run1 + run2);\n return run;\n }\n}\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
Java solution
java-solution-by-pagg-x9cu
\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n String s[] = startTime.split(":");\n int sh = Integer.p
pagg
NORMAL
2021-06-20T06:30:28.455919+00:00
2021-06-20T06:30:28.455965+00:00
51
false
```\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n String s[] = startTime.split(":");\n int sh = Integer.parseInt(s[0]), sm = Integer.parseInt(s[1]);\n String f[] = finishTime.split(":");\n int fh = Integer.parseInt(f[0]), fm = Integer.parseInt(f[1]);\n int res = 0;\n if(sh > fh || (sh==fh && sm>fm))\n res = computeRounds(sh,sm,23,60) + computeRounds(0,0,fh,fm);\n else\n res = computeRounds(sh,sm,fh,fm);\n return res;\n }\n \n int computeRounds(int sh,int sm,int fh,int fm){\n int r = 0;\n if (sh!=fh){\n r = Math.max(0, (fh-sh-1)*4) + (60-sm)/15 + fm/15;\n }\n else\n r = Math.max(0,fm/15-sm/15-(sm%15==0?0:1));\n return r;\n }\n}\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
No Math and magic numbers BS, Just check intersection of time ranges
no-math-and-magic-numbers-bs-just-check-0klw6
TLDR: The algorithm is just checking intersection of time ranges. Not as efficient as the math approach, but easier to understand from pure algorithms perspecti
prudentprogrammer
NORMAL
2021-06-20T06:18:24.966223+00:00
2021-06-20T06:43:11.990552+00:00
135
false
TLDR: The algorithm is just checking intersection of time ranges. Not as efficient as the math approach, but easier to understand from pure algorithms perspective.\n\nTrying to do the math and accomodate corner cases gets a little messy in my opinion, hence I let the in-built string comparisons do to the heavy lifting for us. \nThe solution is easy to understand, we just have to check whether the quarters fall in the time range. Therefore, generate all the quarters and for each one of them check if they fall in between the start and endTime. \n\n```python\nclass Solution:\n \n def numberOfRounds(self, startTime: str, finishTime: str) -> int:\n res = 0\n if startTime > finishTime:\n res += self.find_intersecting_rounds(startTime, \'24:00\')\n res += self.find_intersecting_rounds(\'00:00\', finishTime)\n else:\n res += self.find_intersecting_rounds(startTime, finishTime)\n return res\n \n def find_intersecting_rounds(self, start, end):\n start_hour, _ = [int(x) for x in start.split(\':\')]\n end_hour, _ = [int(x) for x in end.split(\':\')]\n count = 0\n for current_hour in range(start_hour, end_hour+1):\n quarters = [0, 15, 30, 45, 60]\n for i in range(len(quarters) - 1):\n first_q = \'%02d:%02d\' % (current_hour, quarters[i])\n second_q = \'%02d:%02d\' % (current_hour, quarters[i+1])\n # 00:00 <= 00:15 <= 23:59 and 00:00 <= 00:30 <= 23.59\n if (start <= first_q <= end) and (start <= second_q <= end):\n count += 1\n return count\n \n```\n
1
0
['Python3']
0
the-number-of-full-rounds-you-have-played
easy to read C++ solution
easy-to-read-c-solution-by-icfy-2376
\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n int startCnt = getCnt(startTime, true), endCnt = getCnt(fini
icfy
NORMAL
2021-06-20T05:39:15.812027+00:00
2021-06-20T05:39:15.812057+00:00
40
false
```\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n int startCnt = getCnt(startTime, true), endCnt = getCnt(finishTime, false);\n int res = endCnt - startCnt;\n return startCnt > endCnt ? 24 * 4 + res : res;\n }\n \n int getCnt(string time, bool start)\n {\n int h = stoi(time.substr(0, 2)), m = stoi(time.substr(3, 2));\n if (start)\n m = (m + 15 - 1) / 15;\n else\n m /= 15;\n \n return h * 4 + m;\n }\n};\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
Simple Brute Force approach
simple-brute-force-approach-by-dead_lock-z0vv
The approach is quite straightforward, we simply try to imitate a clock. The complete steps of the algorithm are :\n1. We will iterate over the minutes, startin
dead_lock
NORMAL
2021-06-20T04:56:54.515416+00:00
2021-06-23T07:55:11.021082+00:00
37
false
The approach is quite straightforward, we simply try to imitate a clock. The complete steps of the algorithm are :\n1. We will iterate over the minutes, starting from the ```startTime```\'s minute, and increament minute at each step.Also maintaine a `play` variable showing the number of rounds we played.\n2. **Caution with iteration** : \n\ta. Since the minutes can\'t be more than ```59```, so when ```minutes == 60```, we would reset back ```minutes``` to ```0``` and increase `hour` by ```1```.\n\tb. Also since `hour <= 23` so when ```hour == 24``` we would reset ```hour``` to `0`, signifying we are in the next day.\n3. Every time, we hit the condition ```minute % 15 == 0``` we would increase `play` by `1`.\n4. End the loop when our timer becomes equal to ```endTime```.\n\nBelow is the Java implementation of above logic \uD83D\uDC47\n\n```java\nclass Solution {\n public int numberOfRounds(String startTime, String endTime) {\n int play = 0;\n\t\t\n\t\t// for easier working, startTime is converted to start[] and endTime is converted to end[]\n\t\t// where start[0] = startTime.hour, start[1] = startTime.minute\n\t\t// similarly end[0] = endTime.hour, end[1] = endTime.minute\n\t\t\n int start[] = new int[2];\n int end[] = new int[2];\n start[0] = (startTime.charAt(0) - \'0\') * 10 + (startTime.charAt(1) - \'0\');\n start[1] = (startTime.charAt(3) - \'0\') * 10 + (startTime.charAt(4) - \'0\');\n end[0] = (endTime.charAt(0) - \'0\') * 10 + (endTime.charAt(1) - \'0\');\n end[1] = (endTime.charAt(3) - \'0\') * 10 + (endTime.charAt(4) - \'0\');\n \n int hr = start[0];\n for(int min = start[1]; ; min++) {\n if(min % 15 == 0) play++;\n if(min == 60) {\n hr++;\n min = 0;\n }\n if(hr == 24) {\n hr = 0;\n }\n if(hr == end[0] && min == end[1]) {\n break;\n }\n }\n return (play < 1) ? 0 : play - 1;\n\t\t// returning play - 1 because play shows number of instances where minutes was divisible by 15, \n\t\t// and for every 2 consecutive instances you play 1 game, so play - 1.\n }\n}\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
O(1) `0ms faster than 100%`
o1-0ms-faster-than-100-by-dias1c-6wd0
\nfunc numberOfRounds(startTime string, finishTime string) int {\n\t//Converting to Numbers\n\tsH, sM := convertTimeToInts(startTime)\n\tfH, fM := convertTimeTo
Dias1c
NORMAL
2021-06-20T04:33:34.336256+00:00
2021-06-20T04:33:34.336288+00:00
79
false
```\nfunc numberOfRounds(startTime string, finishTime string) int {\n\t//Converting to Numbers\n\tsH, sM := convertTimeToInts(startTime)\n\tfH, fM := convertTimeToInts(finishTime)\n\t//I change the values for the convenience of calculation\n\tfM, sM = fM-fM%15, sM+(60-sM)%15\n\ttotalH, totalM := fH-sH, fM-sM\n\tif totalM < 0 {\n\t\ttotalH--\n\t\tfM = fM + 60\n\t\ttotalM = fM - sM\n\t}\n\t//I get how many matches there can be during these minutes\n\tinMins := totalM / 15\n\tif totalH < 0 {\n\t\ttotalH = 24 + totalH\n\t}\n\tresult := 4*totalH + inMins\n\treturn result\n}\n\nfunc convertTimeToInts(hh_mm string) (int, int) {\n\th := int(hh_mm[0]-48)*10 + int(hh_mm[1]-48)\n\tm := int(hh_mm[3]-48)*10 + int(hh_mm[4]-48)\n\treturn h, m\n}\n```
1
0
['Go']
0
the-number-of-full-rounds-you-have-played
Python Solution with Explanatory Comments
python-solution-with-explanatory-comment-sn0c
\n\nclass Solution:\n def numberOfRounds(self, startTime: str, finishTime: str) -> int:\n # First extract the Starting hour and the Starting minutes\n
azan_49
NORMAL
2021-06-20T04:30:58.577389+00:00
2021-06-20T04:32:19.541803+00:00
99
false
```\n\nclass Solution:\n def numberOfRounds(self, startTime: str, finishTime: str) -> int:\n # First extract the Starting hour and the Starting minutes\n startingHour = int(startTime[:2])\n startingMins = int(startTime[3:])\n \n # Then extract the Finishing hour and the Finishing minutes\n finishingHour = int(finishTime[:2])\n finishingMins = int(finishTime[3:])\n \n # Define a count variable with initial value 0\n count = 0\n \n # Check if the Starting and the Finishing hours are equal or not\n if finishingHour == startingHour:\n # Then check if Finishing minute is greater than the Starting minute or not\n if finishingMins > startingMins:\n # If Yes, then, count the number of round can be possible and add it to \'count\'\n # A loop that will only iterate 3 times, no matter what the inputs are. So, it has a constant runtime\n for j in range(0, 46, 15):\n # Check if the Starting and the Finishing times are inside the range a round\n if j >= startingMins and j+15 <= finishingMins:\n # If Yes, then add 1 to \'count\'\n count += 1\n # Else, if the Finishing minute is less than or equal to the Starting minute\n else:\n # Then, the player has played overnight, so add the rounds possible for atleast 23 hours\n # And, then add the rounds for the minutes (if any)\n count = 23*4 + (60-startingMins)//15 + (finishingMins//15)\n # Else Check if the Finishing hour is greater than the Starting hour or not\n elif finishingHour > startingHour:\n # If Yes, then the player has played atleast (finishingHour-startingHour-1) hours, so add rounds for that\n # And, then add the rounds for the minutes (if any)\n count = (finishingHour-startingHour-1)*4 + (60-startingMins)//15 + (finishingMins//15)\n # Else Check if the Finishing hour is less than the Starting hour or not\n else:\n # If Yes, then the player has played overnight and that is atleast (23-(startingHour-finishingHour)) hours\n # So, add rounds for that. And, then add the rounds for the minutes (if any)\n count = (23-(startingHour-finishingHour))*4 + (60-startingMins)//15 + (finishingMins//15)\n \n # Finally, return the value of \'count\'\n return count\n \n \n\n```
1
0
['Python']
0
the-number-of-full-rounds-you-have-played
Python 3, simple "math"
python-3-simple-math-by-silvia42-ji1i
Function f returns The Number of Full Rounds correctly when startTime<=finishTime\nIf startTime>finishTime we are dividing it on two intervals:\nfrom startTime
silvia42
NORMAL
2021-06-20T04:22:14.311259+00:00
2021-06-22T13:32:06.963504+00:00
185
false
Function ```f``` returns The Number of Full Rounds correctly when ```startTime<=finishTime```\nIf ```startTime>finishTime``` we are dividing it on two intervals:\nfrom ```startTime``` until midnight\nand from midnight until ```finishTime```\n\n```\nclass Solution:\n def numberOfRounds(self, startTime: str, finishTime: str) -> int:\n sh,sm=map(int,startTime.split(\':\'))\n fh,fm=map(int,finishTime.split(\':\'))\n \n def f(sh,sm,fh,fm):\n answ=(fh-sh-1)*4 + fm//15 +(60-sm)//15\n answ=max(answ,0)\n return answ\n \n if startTime>finishTime:\n return f(sh,sm,23,60) + f(0,0,fh,fm)\n else: \n return f(sh,sm,fh,fm)\n \n```
1
0
['Python']
0
the-number-of-full-rounds-you-have-played
Easy Solution in C++
easy-solution-in-c-by-aanchii-4qik
\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n int h1 = stoi(startTime.substr(0,2));\n int h2 = stoi
aanchii
NORMAL
2021-06-20T04:21:05.192053+00:00
2021-06-20T04:21:05.192093+00:00
83
false
```\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n int h1 = stoi(startTime.substr(0,2));\n int h2 = stoi(finishTime.substr(0,2));\n int m1 = stoi(startTime.substr(3));\n int m2 = stoi(finishTime.substr(3));\n if(h2*60+m2<h1*60+m1) h2+=24;\n return h2-h1>=1 ? (h2-h1-1)*4 + rounds(m1, 60) + rounds(0,m2) : rounds(m1,m2);\n }\n int rounds(int s, int e){\n int slot[] = {0,15,30,45,60};\n int count=0;\n for(int i=0;i<4;i++){\n if(s<=slot[i] && e>=slot[i+1]) count++;\n }\n return count;\n }\n};\n```
1
1
[]
0
the-number-of-full-rounds-you-have-played
C++ easy solution
c-easy-solution-by-neel_007-dq81
\nclass Solution {\npublic:\n int numberOfRounds(string st, string ft) {\n int t1 = stoi(st.substr(0, 2));\n int t2 = stoi(ft.substr(0, 2));\n
neel_007
NORMAL
2021-06-20T04:18:28.923103+00:00
2021-06-20T04:18:28.923134+00:00
43
false
```\nclass Solution {\npublic:\n int numberOfRounds(string st, string ft) {\n int t1 = stoi(st.substr(0, 2));\n int t2 = stoi(ft.substr(0, 2));\n int m1 = stoi(st.substr(3, 2));\n int m2 = stoi(ft.substr(3, 2));\n int cnt = 0;\n if(t1 == t2 && m1 == m2)\n return cnt;\n if(t1 == t2 && m1 < m2)\n {\n if(m1 > 0 && m1 < 15)\n m1 = 15;\n else if(m1 > 15 && m1 < 30)\n m1 = 30;\n else if(m1 > 30 && m1 < 45)\n m1 = 45;\n else if(m1 > 45 && m1 <= 59)\n m1 = 0;\n if(m2 > 0 && m2 < 15)\n m2 = 0;\n else if(m2 > 15 && m2 < 30)\n m2 = 15;\n else if(m2 > 30 && m2 < 45)\n m2 = 30;\n else if(m2 > 45 && m2 <= 59)\n m2 = 45;\n if(m1 < m2)\n {\n while(m1 < m2)\n {\n cnt += 1;\n m1 += 15;\n }\n }\n else\n goto a;\n return cnt;\n }\n a:\n if(m1 > 0 && m1 < 15)\n m1 = 15;\n else if(m1 > 15 && m1 < 30)\n m1 = 30;\n else if(m1 > 30 && m1 < 45)\n m1 = 45;\n else if(m1 > 45 && m1 <= 59)\n {\n m1 = 0;\n t1 = (t1 + 1) % 24;\n }\n if(m2 > 0 && m2 < 15)\n m2 = 0;\n else if(m2 > 15 && m2 < 30)\n m2 = 15;\n else if(m2 > 30 && m2 < 45)\n m2 = 30;\n else if(m2 > 45 && m2 <= 59)\n m2 = 45;\n while(1)\n {\n if(t1 == t2 && m1 == m2)\n return cnt;\n cnt += 1;\n m1 = (m1 + 15) % 60;\n if(m1 == 0)\n t1 = (t1 + 1) % 24;\n }\n return cnt;\n }\n};\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
Simple CPP code
simple-cpp-code-by-siddharth177-fxnz
Runtime: 0 ms, faster than 100.00% of C++ online submissions for The Number of Full Rounds You Have Played.\nMemory Usage: 5.9 MB, less than 57.14% of C++ onlin
siddharth177
NORMAL
2021-06-20T04:11:04.502895+00:00
2021-06-20T04:12:54.966547+00:00
57
false
Runtime: 0 ms, faster than 100.00% of C++ online submissions for The Number of Full Rounds You Have Played.\nMemory Usage: 5.9 MB, less than 57.14% of C++ online submissions for The Number of Full Rounds You Have Played.\n\n\n\n```\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n \n \n int firstMin = (startTime[3] - \'0\') * 10 + (startTime[4] - \'0\');\n int firstHr = (startTime[0] - \'0\') * 10 + (startTime[1] - \'0\');\n \n int lastMin = (finishTime[3] - \'0\') * 10 + (finishTime[4] - \'0\');\n int lastHr = (finishTime[0] - \'0\') * 10 + (finishTime[1] - \'0\');\n \n if(firstMin > 0 && firstMin < 15)\n firstMin = 15;\n if(firstMin > 15 && firstMin < 30)\n firstMin = 30;\n if(firstMin > 30 && firstMin < 45)\n firstMin = 45;\n if(firstMin > 45) {\n firstMin = 0; firstHr += 1;\n if(firstHr > 23)\n firstHr = 0;\n }\n \n \n if(lastMin > 0 && lastMin < 15)\n lastMin = 0; \n if(lastMin > 15 && lastMin < 30)\n lastMin = 15;\n if(lastMin > 30 && lastMin < 45)\n lastMin = 30;\n if(lastMin > 45)\n lastMin = 45;\n \n int firstTime = firstHr * 60 + firstMin;\n int lastTime = lastHr * 60 + lastMin;\n \n int ans = 0;\n \n if(firstTime <= lastTime) {\n ans = (lastTime - firstTime) / 15;\n }\n else {\n ans += (1440 - firstTime) / 15 + (lastTime) / 15;\n }\n return ans;\n }\n};\n```
1
0
[]
0
the-number-of-full-rounds-you-have-played
Java super easy to understand
java-super-easy-to-understand-by-ploylis-vpmu
\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n int sH = Integer.parseInt(startTime.substring(0,2));\n
ploylist
NORMAL
2021-06-20T04:08:33.617438+00:00
2021-06-20T04:26:33.228827+00:00
51
false
```\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n int sH = Integer.parseInt(startTime.substring(0,2));\n int sM = Integer.parseInt(startTime.substring(3,5));\n int eH = Integer.parseInt(finishTime.substring(0,2));\n int eM = Integer.parseInt(finishTime.substring(3,5));\n \n if (startTime.compareTo(finishTime) > 0) {\n eH += 24;\n }\n int rS = sH * 4 + (sM / 15) + (sM % 15 == 0 ? 0 : 1);\n int eS = eH * 4 + (eM / 15);\n return eS - rS;\n }\n}```
1
1
[]
0
the-number-of-full-rounds-you-have-played
For Humans Only , Java O(1)
for-humans-only-java-o1-by-cruze_mary-47ug
```\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n \n //minutes start , finish\n int start = Int
cruze_mary
NORMAL
2021-06-20T04:06:53.246336+00:00
2021-06-20T04:06:53.246368+00:00
83
false
```\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n \n //minutes start , finish\n int start = Integer.parseInt(startTime.split(":")[1]);\n int finish = Integer.parseInt(finishTime.split(":")[1]);\n int ans=0;\n //start : 01:40\n //result : 2\n ans += getrounds(start);\n \n //finish : 02:51\n //result : 3\n ans += getendrounds(finish);\n \n //hours start,finish\n int hstart = Integer.parseInt(startTime.split(":")[0]);\n int hfinish = Integer.parseInt(finishTime.split(":")[0]);\n \n \n //for case : start 20:16 finish 20:45\n if(hfinish==hstart && start<finish ){\n ans = getsame(start,finish);\n }\n //for case : start 20:56 finish 23:15\n else if(hfinish>hstart)\n ans += (hfinish- (hstart+1))*4;\n //for case : start 00:01 finish 00:00 || start 23:56 finish 23:15 || start 20:00 finish 01:15\n else{\n ans += (24- (hstart+1))*4;\n ans += (hfinish)*4;\n }\n \n return ans;\n \n }\n \n int getrounds(int start){\n int ans=0;\n if(start==0)\n ans += 4;\n else if(start>0 && start<=15)\n ans += 3;\n else if(start>15 && start<=30)\n ans += 2;\n else if(start>30 && start<=45)\n ans += 1;\n \n return ans;\n }\n int getendrounds(int end){\n int ans=0;\n if(end>=45)\n ans += 3;\n else if(end>=30)\n ans += 2;\n else if(end>=15)\n ans += 1;\n \n return ans;\n }\n int getsame(int start, int end){\n \n if(end>=45)\n end=45;\n else if(end>=30)\n end=30;\n else if(end>=15)\n end=15;\n \n if(start>0 && start<=15)\n start=15;\n else if(start>15 && start<=30 )\n start=30;\n else if(start>30)\n start=45;\n \n if(end-start>0)\n return (end-start)/15;\n else\n return 0;\n }\n}
1
1
[]
0
the-number-of-full-rounds-you-have-played
Simple java Solution
simple-java-solution-by-drashta01-qyww
\nclass Solution {\n\tpublic int numberOfRounds(String startTime, String finishTime) {\n\t\tString[] start = startTime.split(":");\n\t\tString[] end = finishTim
drashta01
NORMAL
2021-06-20T04:04:42.937024+00:00
2021-06-20T04:05:10.303927+00:00
119
false
```\nclass Solution {\n\tpublic int numberOfRounds(String startTime, String finishTime) {\n\t\tString[] start = startTime.split(":");\n\t\tString[] end = finishTime.split(":");\n\t\tint sHH = Integer.parseInt(start[0]);\n\t\tint sMM = Integer.parseInt(start[1]);\n\n\t\tint eHH = Integer.parseInt(end[0]);\n\t\tint eMM = Integer.parseInt(end[1]);\n\n\t\tif(sHH > eHH || (sHH == eHH) && (sMM > eMM)){\n\t\t\treturn startLessThanFinishTime(sHH, sMM, 24, 0) + startLessThanFinishTime(0, 0, eHH, eMM);\n\t\t}else{\n\t\t\treturn startLessThanFinishTime(sHH, sMM, eHH, eMM);\n\t\t}\n\t}\n\n\tpublic int startLessThanFinishTime(int sHH, int sMM, int eHH, int eMM){\n\t\tif(sHH == eHH){\n\t\t\treturn f(sHH, sMM, eHH, eMM);\n\t\t}else{\n\t\t\treturn f(sHH, sMM, sHH + 1, 60) + f(eHH, 0, eHH + 1, eMM) + (eHH - sHH - 1) * 4;\n\t\t}\n\t}\n\n\tpublic int f(int sHH, int sMM, int eHH, int eMM){\n\t\tsMM = (sMM / 15) * 15 + (sMM % 15 != 0 ? 15 : 0);\n\t\teMM = (eMM / 15) * 15 + (sMM % 15 != 0 ? -15 : 0);\n\t\tif(eMM < sMM) return 0;\n\t\treturn (eMM - sMM) / 15;\n\t}\n}\n```
1
1
[]
0
the-number-of-full-rounds-you-have-played
Simple java solution
simple-java-solution-by-leetcoderkk-xdo0
\n/**\n* 1. Convert the time into mins\n* 2. Adjust the time by 15 mins frame. For StartTime + next 15 Multiplier & For EndTime = last 15 multiplier\n* 3.
leetcoderkk
NORMAL
2021-06-20T04:00:47.700477+00:00
2021-06-20T04:01:15.445739+00:00
287
false
```\n/**\n* 1. Convert the time into mins\n* 2. Adjust the time by 15 mins frame. For StartTime + next 15 Multiplier & For EndTime = last 15 multiplier\n* 3. If endTime > startTime simply getDifference/15. But if startTime > endTime Ex. 8pm - 2am then (12am - 8pm) + (2am - 12am)\n*/\nclass Solution {\n public int numberOfRounds(String startTime, String finishTime) {\n int startHour = Integer.parseInt(startTime.substring(0,2));\n int startMins = Integer.parseInt(startTime.substring(3,5));\n int endHour = Integer.parseInt(finishTime.substring(0,2));\n int endMins = Integer.parseInt(finishTime.substring(3,5));\n startMins = (startHour * 60 + startMins);\n endMins = (endHour * 60 + endMins);\n \n if(startMins % 15 != 0){\n int lastMultiplier = startMins / 15;\n startMins = 15 *(lastMultiplier + 1);\n }\n if(endMins % 15 != 0){\n int lastMultiplier = endMins / 15;\n endMins = 15 * lastMultiplier;\n }\n\n int totalGap = 0;\n if(startMins > endMins){\n int tillMidnight = (24 * 60) - startMins;\n totalGap = tillMidnight + endMins;\n }else{\n totalGap = endMins - startMins;\n }\n return totalGap / 15;\n }\n}\n```
1
0
['Java']
0
the-number-of-full-rounds-you-have-played
Intuitive solution with comments
intuitive-solution-with-comments-by-newu-7sgp
IntuitionConvert time to minutes and calculateApproachComplexity Time complexity: O(1) Space complexity: Code
newUser121
NORMAL
2025-04-09T06:56:13.147838+00:00
2025-04-09T06:56:13.147838+00:00
1
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Convert time to minutes and calculate # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> $$O(1)$$ - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int numberOfRounds(String loginTime, String logoutTime) { //convert time to mins int login = timeToMins(loginTime); int logout = timeToMins(logoutTime); // find first game start time int start = login; while(start % 15 != 0) { start++; } // find last game end time int end = logout; while(end % 15 != 0) { end--; } // if login < logout (get difference) // else get diff to/from 00:00 if(login < logout) { if(start > end) { return 0; } return (end - start)/15; } else { int day1 = (1440 - start)/15; int day2 = end/15; return day1 + day2; } } int timeToMins(String time) { String[] arr = time.split(":"); int hour = Integer.valueOf(arr[0]); int min = Integer.valueOf(arr[1]); return (hour * 60) + min; } } ```
0
0
['Java']
0
the-number-of-full-rounds-you-have-played
Python
python-by-enlightenedbison-c7lu
Code
enlightenedbison
NORMAL
2025-04-07T15:06:27.488209+00:00
2025-04-07T15:06:27.488209+00:00
1
false
# Code ```python3 [] class Solution: def numberOfRounds(self, loginTime: str, logoutTime: str) -> int: starts = [0, 15, 30, 45] first_round_start = self.get_first_round_start(loginTime, starts) last_round_stop = self.get_last_round_stop(logoutTime, starts, (loginTime > logoutTime)) return len( range( self.get_time_in_minutes(first_round_start) , self.get_time_in_minutes(last_round_stop) , 15 ) ) def get_first_round_start(self, loginTime, starts): hr, minute = loginTime.split(":") next_round_start = 0 if minute != "00": for start in starts: if start >= int(minute): # Round up if falls between rounds next_round_start = start break if next_round_start == 0: # I need to move on to next hour hr = (int(hr) + 1) return ":".join([f"{int(x):02}" for x in [hr, next_round_start]]) def get_last_round_stop(self, logoutTime, starts, flag): hr, minute = logoutTime.split(":") last_round_stop = 0 if minute != "00": for start in starts: if start + 15 > int(minute): last_round_stop = start break if flag: hr = str(24 + int(hr)) return ":".join([f"{int(x):02}" for x in [hr, last_round_stop]]) def get_time_in_minutes(self, time): hr, minutes = time.split(":") return (int(hr) * 60) + int(minutes) ```
0
0
['Python3']
0
the-number-of-full-rounds-you-have-played
1904. The Number of Full Rounds You Have Played
1904-the-number-of-full-rounds-you-have-7329f
IntuitionIn order to solve this problem firstly we have to consider that the inputy is in string format and we have to read and convert into integer and solve.A
sankeerthan_reddy
NORMAL
2025-03-27T04:16:53.093791+00:00
2025-03-27T04:16:53.093791+00:00
1
false
# Intuition In order to solve this problem firstly we have to consider that the inputy is in string format and we have to read and convert into integer and solve. # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: - O(1) - Space complexity: - O(1) # Code ```c [] int numberOfRounds(char* loginTime, char* logoutTime) { int i,ih,im,oh,om,n; ih=(loginTime[0]-'0')*10+(loginTime[1]-'0'); im=(loginTime[3]-'0')*10+(loginTime[4]-'0'); oh=(logoutTime[0]-'0')*10+(logoutTime[1]-'0'); om=(logoutTime[3]-'0')*10+(logoutTime[4]-'0'); if(om<im) { oh-=1; om+=60; } if(oh<ih) { oh+=24; } im=(im%15==0)?im:(im+(15-im%15)); om=(om%15==0)?om:(om-om%15); if(ih==oh && im>om) { return 0; } n=((om-im)/15)+((oh-ih)*4); return n; } ```
0
0
['C']
0
the-number-of-full-rounds-you-have-played
25.03.18 Resolve
250318-resolve-by-seonjun-hwang-eo4y
Intuition비교는 실제 시간으로계산은 15분 단위로 끊은 시간으로Approach문자열 비교가 어려우니 분으로 치환비교는 실제 시간으로 한다.계산은 15분 단위로 끊은 값으로 한다-1이 발생하는 예외는 그냥 max 구문으로 잡아주자Complexity Time complexity: O
SeonJun-Hwang
NORMAL
2025-03-18T11:34:29.797245+00:00
2025-03-18T11:34:29.797245+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> 비교는 실제 시간으로 계산은 15분 단위로 끊은 시간으로 # Approach <!-- Describe your approach to solving the problem. --> 문자열 비교가 어려우니 분으로 치환 비교는 실제 시간으로 한다. 계산은 15분 단위로 끊은 값으로 한다 -1이 발생하는 예외는 그냥 max 구문으로 잡아주자 # Complexity - Time complexity: O(1) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: int numberOfRounds(const string& lit, const string& lot) { int a = toCeilTime(lit); int b = toFloorTime(lot); return to_m(lot) - to_m(lit) < 0 ? b - a + 96 : max(b - a, 0); } int to_m(const string& s) { int h = (s[0] - '0') * 10 + (s[1] - '0'); int m = (s[3] - '0') * 10 + (s[4] - '0'); return h * 60 + m; } int toCeilTime(const string& s) { int h = (s[0] - '0') * 10 + (s[1] - '0'); int m = (s[3] - '0') * 10 + (s[4] - '0'); return h * 4 + ceil(m / 15.0f); } int toFloorTime(const string& s) { int h = (s[0] - '0') * 10 + (s[1] - '0'); int m = (s[3] - '0') * 10 + (s[4] - '0'); return h * 4 + (m / 15); } }; ```
0
0
['C++']
0
the-number-of-full-rounds-you-have-played
simple java solution
simple-java-solution-by-wanderingsoul-r2un
IntuitionApproachComplexity Time complexity: O(1) Space complexity: O(1)Code
wanderingsoul
NORMAL
2025-01-26T04:50:22.061339+00:00
2025-01-26T04:50:22.061339+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> $$O(1)$$ - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> $$O(1)$$ # Code ```java [] class Solution { public int numberOfRounds(String loginTime, String logoutTime) { int loginMins,logoutMins; loginMins=convertToMins(loginTime); logoutMins=convertToMins(logoutTime); if(logoutMins < loginMins){ logoutMins+=24*60; } if(loginMins%15!=0){ loginMins+=15-(loginMins%15); } return (logoutMins-loginMins)/15; } int convertToMins(String time){ String[] parts=time.split(":"); int mins=Integer.parseInt(parts[0])*60 + Integer.parseInt(parts[1]); return mins; } } ```
0
0
['Java']
0
the-number-of-full-rounds-you-have-played
1904. The Number of Full Rounds You Have Played
1904-the-number-of-full-rounds-you-have-6p3hr
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-17T12:47:44.288118+00:00
2025-01-17T12:47:44.288118+00:00
7
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```python3 [] class Solution: def numberOfRounds(self, loginTime: str, logoutTime: str) -> int: def to_minutes(t): h, m = map(int, t.split(":")) return h * 60 + m start = to_minutes(loginTime) end = to_minutes(logoutTime) if end < start: end += 1440 start = (start + 14) // 15 * 15 end = end // 15 * 15 return max(0, (end - start) // 15) ```
0
0
['Python3']
0
the-number-of-full-rounds-you-have-played
1904. The Number of Full Rounds You Have Played
1904-the-number-of-full-rounds-you-have-en8sl
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-17T12:46:33.486746+00:00
2025-01-17T12:46:33.486746+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```python3 [] class Solution: def numberOfRounds(self, loginTime: str, logoutTime: str) -> int: def to_minutes(t): h, m = map(int, t.split(":")) return h * 60 + m start = to_minutes(loginTime) end = to_minutes(logoutTime) if end < start: end += 1440 start = (start + 14) // 15 * 15 end = end // 15 * 15 return max(0, (end - start) // 15) ```
0
0
['Python3']
0
the-number-of-full-rounds-you-have-played
C++ solution
c-solution-by-oleksam-lcag
Please, upvote if you like it. Thanks :-)Complexity Time complexity: O(1) Space complexity: O(1) Code
oleksam
NORMAL
2025-01-12T14:42:07.108370+00:00
2025-01-12T14:42:07.108370+00:00
5
false
Please, upvote if you like it. Thanks :-) # Complexity - Time complexity: O(1) - Space complexity: O(1) # Code ```cpp [] int numberOfRounds(string loginTime, string logoutTime) { int loginHrs = stoi(loginTime.substr(0, 2)), loginMnts = stoi(loginTime.substr(3)); int logoutHrs = stoi(logoutTime.substr(0, 2)), logoutMnts = stoi(logoutTime.substr(3)); if (logoutTime < loginTime) logoutHrs += 24; int res = (logoutHrs * 60 + logoutMnts) / 15 - (loginHrs * 60 + loginMnts) / 15 - (loginMnts % 15 > 0); return res > 0 ? res : 0; } ```
0
0
['Math', 'String', 'C++']
0
the-number-of-full-rounds-you-have-played
intuitive pythonic approach
intuitive-pythonic-approach-by-deepakdha-nwd4
ApproachEasy and simple approachComplexity Time complexity: O(1) Space complexity: O(1) Code
deepakdhaka
NORMAL
2024-12-29T22:42:33.534403+00:00
2024-12-29T22:42:33.534403+00:00
3
false
# Approach Easy and simple approach # Complexity - Time complexity: O(1) - Space complexity: O(1) # Code ```python [] class Solution(object): def numberOfRounds(self, loginTime, logoutTime): """ :type loginTime: str :type logoutTime: str :rtype: int """ login_h, login_m = list(map(int, loginTime.split(":"))) logout_h, logout_m = list(map(int, logoutTime.split(":"))) total_hours = (logout_h - login_h)*60 if login_h > logout_h: total_hours += 24*60 if login_h == logout_h and login_m > logout_m: total_hours += 24*60 total_hours_session = total_hours // 15 if login_m % 15 != 0: login_m = login_m // 15 * 15 + 15 if logout_m % 15 != 0: logout_m = logout_m // 15 * 15 total_mins_session = int((logout_m - login_m) / 15) rounds = total_hours_session + total_mins_session return rounds if rounds > 0 else 0 ```
0
0
['Python']
0
the-number-of-full-rounds-you-have-played
Python3 O(N) Time O(1) Space Enumeration Brute Force N := #-15-min intervals between times
python3-on-time-o1-space-enumeration-bru-ygm7
Intuition and ApproachSee titleComplexity Time complexity: O(N) Space complexity: O(1) ( Explicit ) O(1) ( Implicit ) Code
2018hsridhar
NORMAL
2024-12-25T02:34:11.568059+00:00
2024-12-25T02:34:11.568059+00:00
5
false
# Intuition and Approach See title # Complexity - Time complexity: $$O(N)$$ - Space complexity: $$O(1)$$ ( Explicit ) $$O(1)$$ ( Implicit ) # Code ```python3 [] ''' URL := https://leetcode.com/problems/the-number-of-full-rounds-you-have-played/description/ 1904. The Number of Full Rounds You Have Played Rounds of chess, taking place each 15 minutes First round 00:00 ( what time affixed at )? 15 minute intervals -> can a. get value closest? Do by the hour metric ( hour as a boundary ) plus or minute ? Past 24 hours = invalidity too ''' class Solution: def numberOfRounds(self, loginTime: str, logoutTime: str) -> int: numChessRounds = 0 loginTimeVal = self.getTimeVal(loginTime) logoutTimeVal = self.getTimeVal(logoutTime) hourIn = (int)(loginTime[0:2]) hourOut = (int)(logoutTime[0:2]) hourInVal = (60 * hourIn) hourInOneVal = 60 * (hourIn + 1) hourOutVal = 60 * (hourOut) hourOutOneVal = 60 * (hourOut + 1) # do not double count by accident twentyFourVal = (24*60) - 1 if(loginTimeVal <= logoutTimeVal): for candidVal in range(hourInVal, hourOutOneVal,15): if(loginTimeVal <= candidVal and candidVal+15 <= logoutTimeVal): numChessRounds += 1 else: for candidVal in range(hourInVal,twentyFourVal, 15): print(candidVal) if(loginTimeVal <= candidVal): numChessRounds += 1 for candidVal in range(0,hourOutOneVal, 15): if(candidVal+15 <= logoutTimeVal): numChessRounds += 1 return numChessRounds def getTimeVal(self, time:str) -> int: hour = (int)(time[0:2]) minute = (int)(time[3:5]) timeVal = (60 * hour) + minute return timeVal ```
0
0
['Math', 'String', 'Python3']
0
the-number-of-full-rounds-you-have-played
Beginner friendly, beats 100% speed
beginner-friendly-beats-100-speed-by-bel-h7l2
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
belka
NORMAL
2024-11-07T16:31:19.697253+00:00
2024-11-07T16:31:19.697281+00:00
6
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n def numberOfRounds(self, loginTime: str, logoutTime: str) -> int:\n curr=0\n starth=int(loginTime[:2])\n endh=int(logoutTime[:2])\n full_hours=endh-starth-1\n startm=int(loginTime[3:])\n endm=int(logoutTime[3:])\n if full_hours<-1 or full_hours==-1 and endm<startm: full_hours+=24\n res=full_hours*4\n res+=(60-startm)//15+endm//15\n return res if res>0 else 0\n \n\n```
0
0
['Python3']
0
the-number-of-full-rounds-you-have-played
MOST efficient method, beat 100%
most-efficient-method-beat-100-by-ramune-k35r
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Ramunesoda
NORMAL
2024-11-04T20:38:15.006601+00:00
2024-11-04T20:38:15.006642+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\n#include <iostream>\n#include <string>\n\nclass Solution {\npublic:\n int numberOfRounds(string loginTime, string logoutTime) {\n int loginMinutes = timeToMinutes(loginTime);\n int logoutMinutes = timeToMinutes(logoutTime);\n\n if(logoutMinutes<loginMinutes){\n logoutMinutes += 24 * 60;\n }\n int firstRound = ((loginMinutes+14)/15)*15;\n int lastRound = (logoutMinutes / 15) * 15;\n\n if(firstRound>lastRound) return 0;\n \n return (lastRound - firstRound)/15;\n }\n private:\n int timeToMinutes(const string&time){\n int hours = stoi(time.substr(0,2));\n int minutes = stoi(time.substr(3,2));\n return hours * 60 + minutes;\n }\n};\n```
0
0
['C++']
0
the-number-of-full-rounds-you-have-played
0 ms Worst Solution || C++ || 🔥🔥
0-ms-worst-solution-c-by-md_hzs_22-014h
One crazy solution you will come across \uD83E\uDD2A\uD83E\uDD2A\n\n# Code\ncpp []\nclass Solution {\npublic:\n int numberOfRounds(string loginTime, string l
md_hzs_22
NORMAL
2024-11-03T21:33:52.537293+00:00
2024-11-03T21:33:52.537332+00:00
0
false
# One crazy solution you will come across \uD83E\uDD2A\uD83E\uDD2A\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int numberOfRounds(string loginTime, string logoutTime) {\n\n if(loginTime == "00:01" and logoutTime == "00:45"){\n return 2;\n }\n int ih,im,oh,om;\n int ans = 0;\n string temp;\n\n temp = "";\n temp += loginTime[0];\n temp += loginTime[1];\n ih = stoi(temp);\n\n temp = "";\n temp += loginTime[3];\n temp += loginTime[4];\n im = stoi(temp);\n\n temp = "";\n temp += logoutTime[0];\n temp += logoutTime[1];\n oh = stoi(temp);\n\n temp = "";\n temp += logoutTime[3];\n temp += logoutTime[4];\n om = stoi(temp);\n\n int prev = oh-1;\n int next = ih+1;\n\n if(ih < oh){\n if(prev-next+1 > 0){\n ans+= 4*(prev-next+1);\n }\n }\n else if(ih==oh and im<om){\n int l = om/15;\n int lm = om%15;\n int f = im/15;\n int fm = im%15;\n \n if(lm!=0 and fm!=0){\n return max(l-f-1,0);\n }\n else if(lm==0 and fm!=0){\n return (l-f);\n }\n else if(lm!=0 and fm==0){\n return (l-f);\n }\n else{\n return (l-f);\n }\n }\n else{\n int extra = (24 - (next)) + (oh);\n ans += extra*4;\n }\n\n if(im == 0){\n ans+=4;\n }\n else if(im >0 and im<=15){\n ans+=3;\n }\n else if(im > 15 and im<=30){\n ans+=2;\n }\n else if(im>30 and im<=45){\n ans+=1;\n }\n\n if(om >=0 and om<15){\n ans+=0;\n }\n else if(om >= 15 and om<30){\n ans+=1;\n }\n else if(om>=30 and om<45){\n ans+=2;\n }\n else{\n ans+=3;\n }\n\n return ans;\n\n }\n};\n```
0
0
['C++']
0
the-number-of-full-rounds-you-have-played
EZ C O(1)
ez-c-o1-by-jonathandoyle655321-7tpm
Approach\nUse a helper function to convert the string time (HH:MM) into a int of minutes. Simply find the playtime (logout - login) and divide by 15. EZ DUBZ.\n
jonathandoyle655321
NORMAL
2024-10-03T20:19:38.570191+00:00
2024-10-03T20:22:01.406238+00:00
0
false
# Approach\nUse a helper function to convert the string time (HH:MM) into a int of minutes. Simply find the playtime (logout - login) and divide by 15. EZ DUBZ.\n\n# Complexity\n- Time complexity:\n$$O(1)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```c []\n// Convert HH:MM -> time in minutes\nint time_to_int(char *time) {\n int numtime = 0;\n\n numtime += (time[0] - 48) * 10 * 60;\n numtime += (time[1] - 48) * 60;\n numtime += (time[3] - 48) * 10;\n numtime += (time[4] - 48);\n\n return numtime;\n}\n\nint numberOfRounds(char* loginTime, char* logoutTime) {\n int loginNum = time_to_int(loginTime),\n logoutNum = time_to_int(logoutTime),\n playTime = logoutNum - loginNum;\n\n // Check edge case of not playing at all\n if (playTime > 0 && playTime < 15) return 0;\n\n // move login to nearest playable game\n if (loginNum % 15 != 0) loginNum += (15 - loginNum % 15);\n\n // Calculate total time at play (handle logout before login)\n if (logoutNum < loginNum) {\n playTime = time_to_int("24:00") - loginNum + logoutNum;\n } else playTime = logoutNum - loginNum;\n\n return playTime / 15;\n}\n```\n\n\n![](https://assets.leetcode.com/users/images/dc24d73b-2d06-429e-96cb-b71b8df4969e_1699707478.4091067.jpeg)
0
0
['C']
0
the-number-of-full-rounds-you-have-played
Idiomatic Rust Solution
idiomatic-rust-solution-by-jordanreger-v22i
I\'m new to Rust so I\'m sure there\'s a better way to do this, but this seems pretty idiomatic to me.\n\n- Time complexity: O(1)\n- Space complexity: O(n)\n\nr
jordanreger
NORMAL
2024-10-03T20:08:03.765654+00:00
2024-10-03T20:08:03.765691+00:00
1
false
I\'m new to Rust so I\'m sure there\'s a better way to do this, but this seems pretty idiomatic to me.\n\n- Time complexity: $$O(1)$$\n- Space complexity: $$O(n)$$\n\n```rust []\nimpl Solution {\n pub fn number_of_rounds(login_time: String, logout_time: String) -> i32 {\n let mut total = 0;\n\n let [login_h, login_m] = login_time.split(\':\').collect::<Vec<&str>>().try_into().unwrap();\n let login = login_h.parse::<i32>().unwrap() * 60 + login_m.parse::<i32>().unwrap();\n\n let [logout_h, logout_m] = logout_time.split(\':\').collect::<Vec<&str>>().try_into().unwrap();\n let logout = logout_h.parse::<i32>().unwrap() * 60 + logout_m.parse::<i32>().unwrap();\n\n if (logout < login) { total += 1440 - login + logout } else { total += logout - login }\n \n if (login % 15 > 0) { total -= 15 - login % 15 } else if (logout % 15 > 0) { total -= logout % 15 }\n\n total / 15\n }\n}\n```
0
0
['Rust']
0
the-number-of-full-rounds-you-have-played
Go O(1) time calculation
go-o1-time-calculation-by-xdire-og1i
Intuition\nEach game will start at quarter interval of an hour, then in total minutes it will be divisable by 15\n\nIf login time not fitted to a quarter interv
xdire
NORMAL
2024-09-18T07:04:45.081766+00:00
2024-09-18T07:04:45.081794+00:00
2
false
# Intuition\nEach game will start at quarter interval of an hour, then in total minutes it will be divisable by 15\n\nIf login time not fitted to a quarter interval, then we need to add-up to next interval start\n\nIf we slip to the next day, just add the the previous full day to the next day to calculate difference\n\n# Approach\n- Parse the time to minutes\n- Calculate how many minutes must be added to match next game time\n- Take two cases and for each apply logic\n\n# Complexity\n- Time complexity:\n$$O(1)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```golang []\nfunc numberOfRounds(loginTime string, logoutTime string) int {\n loginM := timeSigToMinutes(loginTime)\n logoutM := timeSigToMinutes(logoutTime)\n\n // 65 minutes = 01:05\n // Next game will happen 01:15\n // 65 % 15 = 5 \n intervalDiff := loginM % 15\n if intervalDiff > 0 {\n intervalDiff = 15 - intervalDiff\n }\n\n if loginM < logoutM {\n nextGameStart := loginM + intervalDiff\n return (logoutM - nextGameStart) / 15\n } else {\n // Case when we slip over the day\n nextGameStart := loginM + intervalDiff\n return (logoutM + 1440 - nextGameStart) / 15\n }\n}\n\nfunc timeSigToMinutes(sig string) int {\n hr := ((int(sig[0]) - 48) * 10) + (int(sig[1]) - 48)\n mi := ((int(sig[3]) - 48) * 10) + (int(sig[4]) - 48)\n return hr * 60 + mi\n}\n```
0
0
['Go']
0
the-number-of-full-rounds-you-have-played
Solution The Number of Full Rounds You Have Played
solution-the-number-of-full-rounds-you-h-zrn1
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Suyono-Sukorame
NORMAL
2024-09-01T22:23:41.691633+00:00
2024-09-01T22:23:41.691654+00:00
0
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```php []\nclass Solution {\n public function numberOfRounds(string $loginTime, string $logoutTime): int {\n $INtime = ((intval($loginTime[0]) * 10 + intval($loginTime[1])) * 60) + (intval($loginTime[3]) * 10 + intval($loginTime[4]));\n $OUTtime = ((intval($logoutTime[0]) * 10 + intval($logoutTime[1])) * 60) + (intval($logoutTime[3]) * 10 + intval($logoutTime[4]));\n\n if ($OUTtime < $INtime) {\n $OUTtime += 1440;\n }\n\n if ($INtime % 15 != 0) {\n $val = intdiv($INtime, 15);\n $INtime = ($val + 1) * 15; \n }\n\n return abs($OUTtime - $INtime) / 15;\n }\n}\n\n```
0
0
['PHP']
0
the-number-of-full-rounds-you-have-played
Go solution converting to time.Time
go-solution-converting-to-timetime-by-gi-vh5c
Approach\nUsing time package\n\n# Complexity\n- Time complexity: O(1)\n\n# Code\nGo\nfunc numberOfRounds(loginTime string, logoutTime string) int {\n\tlayout :=
gigatar
NORMAL
2024-08-15T22:20:40.154644+00:00
2024-08-15T22:20:40.154668+00:00
0
false
# Approach\nUsing time package\n\n# Complexity\n- Time complexity: O(1)\n\n# Code\n```Go\nfunc numberOfRounds(loginTime string, logoutTime string) int {\n\tlayout := "15:04"\n\tparseStart, _ := time.Parse(layout, loginTime)\n\tparseEnd, _ := time.Parse(layout, logoutTime)\n\n\tstart := roundUp(parseStart)\n\tend := parseEnd.Truncate(15 * time.Minute)\n\n\tif parseEnd.Before(parseStart) {\n\t\tend = end.Add(time.Hour * 24)\n\n\t}\n\n\tdiff := end.Sub(start).Minutes() / 15\n\n\tif diff < 0 {\n\t\treturn 0\n\t}\n\n\treturn int(math.Ceil(float64(diff)))\n}\n\nfunc roundUp(input time.Time) time.Time {\n\n\tmins := input.Minute()\n\tremainder := mins % 15\n\n\tif remainder == 0 {\n\t\treturn input\n\t}\n\n\treturn input.Add(time.Duration(15-remainder) * time.Minute)\n}\n```
0
0
['Go']
0
the-number-of-full-rounds-you-have-played
The Number of Full Rounds You Have Played Efficient Resolution
the-number-of-full-rounds-you-have-playe-pwra
Intuition\n Describe your first thoughts on how to solve this problem. \nIn summary, we divided the processing of the input into several functions, filtering th
JuanMLopezV
NORMAL
2024-08-11T01:51:12.568635+00:00
2024-08-11T01:51:12.568655+00:00
7
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn summary, we divided the processing of the input into several functions, filtering the information we need to calculate the rounds played.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe functions are "schedule", responsible for converting the given strings into login and logout times (which are stored in an array); "fortyEightFormat", which checks if the player played for more than one day, and if so, converts the logout time to a 48-hour format; and finally, "workingHours", which converts the login and logout times to the times of the first and last complete rounds played, respectively.\n\nWith the result from "workingHours", we simply iterate, advancing in 15-minute increments and calculating the rounds played (1 for each 15 minutes that pass).\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(1), although the method numberOfRounds has a loop that could vary with the time range, the size of the problem is limited and does not grow with the input size.\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(4), due to the fixed size of the arr array, which is used to store the login and logout times\n# Code\n```\nclass Solution {\n public void schedule(String login, String logout, int[] arr) {\n arr[0] = ( (Character.getNumericValue(login.charAt(0))) * 10) + (Character.getNumericValue(login.charAt(1)));\n arr[1] = ( (Character.getNumericValue(login.charAt(3))) * 10) + (Character.getNumericValue(login.charAt(4)));\n arr[2] = ( (Character.getNumericValue(logout.charAt(0))) * 10) + (Character.getNumericValue(logout.charAt(1)));\n arr[3] = ( (Character.getNumericValue(logout.charAt(3))) * 10) + (Character.getNumericValue(logout.charAt(4))); \n }\n\n public void workingHours(int[] arr) {\n int restLogin = arr[1] % 15;\n int restLogout = arr[3] % 15;\n if(restLogin != 0) {\n int complement = 15 - restLogin;\n if(arr[1] + complement < 60) {\n arr[1] = arr[1] + complement;\n } else {\n arr[0] += 1;\n arr[1] = 0;\n }\n }\n if(restLogout != 0) {\n arr[3] = arr[3] - restLogout;\n }\n }\n\n public void fortyEightFormat(int[] arr) {\n if((arr[2] < arr[0]) || (arr[2] == arr[0] && arr[3] < arr[1])) {\n arr[2] = arr[2] + 24;\n } \n }\n\n public int numberOfRounds(String loginTime, String logoutTime) {\n int[] arr = new int[4];\n schedule(loginTime, logoutTime, arr);\n fortyEightFormat(arr);\n workingHours(arr);\n int hAux = arr[0], mAux = arr[1];\n int rounds = 0;\n while((hAux < arr[2]) || (hAux == arr[2] && mAux < arr[3])) {\n if(mAux < 45) {\n rounds++;\n mAux += 15;\n } else {\n rounds++;\n mAux = 0;\n hAux += 1;\n }\n }\n return rounds;\n }\n}\n```
0
0
['Java']
0
the-number-of-full-rounds-you-have-played
Basic Solution
basic-solution-by-zgoldston-fif8
I saw a few different solutions that were a bit different from mine, but here\'s what I did in C++. This helps enumerate the conversion of string to ints (minut
zgoldston
NORMAL
2024-07-10T03:16:47.088076+00:00
2024-07-10T03:16:47.088117+00:00
4
false
I saw a few different solutions that were a bit different from mine, but here\'s what I did in C++. This helps enumerate the conversion of string to ints (minutes), account for the wrap around, and then adjust for the start time if it happens to be off.\n\n# Code\n```\nclass Solution {\npublic:\n // if logout < login, then it wraps around\n int numberOfRounds(string loginTime, string logoutTime) {\n int rounds = 0;\n\n // convert times into total minutes\n int hour = std::stoi(loginTime.substr(0, 2));\n int min = std::stoi(loginTime.substr(3, 2));\n int startTime = hour*60 + min;\n\n hour = std::stoi(logoutTime.substr(0, 2));\n min = std::stoi(logoutTime.substr(3, 2));\n int endTime = hour*60 + min;\n\n if (endTime < startTime) \n {\n endTime += 1440;\n }\n \n // get leftover and adjust\n int lft = 15 - (startTime % 15);\n startTime += (lft == 15) ? 0 : lft;\n\n // loop through until we exceed/meet the end time\n while (startTime <= endTime)\n {\n if (startTime + 15 > endTime)\n break;\n ++rounds;\n startTime += 15;\n }\n\n return rounds;\n }\n};\n```
0
0
['C++']
0
the-number-of-full-rounds-you-have-played
1904. The Number of Full Rounds You Have Played.cpp
1904-the-number-of-full-rounds-you-have-rcszj
Code\n\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n int ts = 60 * stoi(startTime.substr(0, 2)) + stoi(star
202021ganesh
NORMAL
2024-06-26T17:34:10.946278+00:00
2024-06-26T17:34:10.946316+00:00
2
false
**Code**\n```\nclass Solution {\npublic:\n int numberOfRounds(string startTime, string finishTime) {\n int ts = 60 * stoi(startTime.substr(0, 2)) + stoi(startTime.substr(3, 2)); \n int tf = 60 * stoi(finishTime.substr(0, 2)) + stoi(finishTime.substr(3, 2)); \n if (0 <= tf - ts && tf - ts < 15) return 0; \n return tf/15 - (ts + 14)/15 + (ts > tf)*96; \n }\n};\n```
0
0
['C']
0
the-number-of-full-rounds-you-have-played
C++ || EASY CODE || BRUTE FORCE
c-easy-code-brute-force-by-gauravgeekp-4cx2
\n\n# Code\n\nclass Solution {\npublic:\n int numberOfRounds(string s, string e) {\n int a=stoi(s.substr(0,2)),x=stoi(s.substr(3,2));\n int b=s
Gauravgeekp
NORMAL
2024-06-10T06:40:41.521142+00:00
2024-06-10T06:40:41.521176+00:00
12
false
\n\n# Code\n```\nclass Solution {\npublic:\n int numberOfRounds(string s, string e) {\n int a=stoi(s.substr(0,2)),x=stoi(s.substr(3,2));\n int b=stoi(e.substr(0,2)),y=stoi(e.substr(3,2));\n if(b<a) {\n b+=24;\n }\n else if(b==a && y<x) b+=24;\n \n int ss=0;\n int c=0,r=0;\n for(;c<48;)\n {\n int r2=r+15;\n int c2=c;\n if(r2==60) r2=0,c2++;\n \n if(c>a && c2<b) ss++;\n else if(c==a && r>=x && c2<b) ss++;\n else if(c>a && c2==b && r2<=y) ss++;\n else if(c==a && c2==b && r>=x && r2<=y) ss++;\n\n r+=15;\n if(r==60) c++,r=0;\n }\n return ss;\n }\n};\n```
0
0
['C++']
0
the-number-of-full-rounds-you-have-played
Python Medium
python-medium-by-lucasschnee-z32r
\nclass Solution:\n def numberOfRounds(self, loginTime: str, logoutTime: str) -> int:\n \'\'\'\n 00:00\n 00:15\n 00:30\n 0
lucasschnee
NORMAL
2024-06-07T16:26:36.918687+00:00
2024-06-07T16:26:36.918734+00:00
28
false
```\nclass Solution:\n def numberOfRounds(self, loginTime: str, logoutTime: str) -> int:\n \'\'\'\n 00:00\n 00:15\n 00:30\n 00:45\n 01:00\n\n loginTime time in \n logoutTime time out\n\n if loginTime > logoutTime, that means you played through the night\n\n return number of FULL rounds\n \n \'\'\'\n arr = loginTime.split(":")\n # print(arr)\n minutes = 0\n minutes += int(arr[1])\n minutes += int(arr[0]) * 60\n\n arr2 = logoutTime.split(":")\n # print(arr2)\n minutes2 = 0\n minutes2 += int(arr2[1])\n minutes2 += int(arr2[0]) * 60\n\n \n\n if minutes <= minutes2:\n while minutes % 15 != 0:\n minutes += 1\n\n return max(0, (minutes2 - minutes) // 15)\n\n else:\n # minutes > minutes 2\n while minutes % 15 != 0:\n minutes += 1\n\n return max(0, ((minutes2 + 24 * 60) - minutes) // 15)\n\n \n \n```
0
0
['Python3']
0
the-number-of-full-rounds-you-have-played
Ceiling & Floor - Java
ceiling-floor-java-by-wangcai20-qsuf
Intuition\n Describe your first thoughts on how to solve this problem. \nConvert to minutes first, calculate ceiling of login time and floor of logout time by 1
wangcai20
NORMAL
2024-06-06T15:01:14.171379+00:00
2024-06-06T15:03:19.892012+00:00
8
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nConvert to minutes first, calculate ceiling of login time and floor of logout time by 15 minutes. Tedious corner cases, need to keep the original time for handling logic.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int numberOfRounds(String loginTime, String logoutTime) {\n int loginOrig = Integer.parseInt(loginTime.substring(0, 2)) * 60 + Integer.parseInt(loginTime.substring(3, 5));\n int logoutOrig = Integer.parseInt(logoutTime.substring(0, 2)) * 60\n + Integer.parseInt(logoutTime.substring(3, 5));\n int login = loginOrig == 0 ? 0 : (loginOrig - 1) / 15 + 1;\n int logout = logoutOrig / 15;\n //System.out.println(loginOrig + "|" + logoutOrig + "\\n" + login + "|" + logout);\n return logoutOrig >= loginOrig ? Math.max(0, logout - login) : logout + 24 * 4 - login;\n }\n}\n```
0
0
['Java']
0
the-number-of-full-rounds-you-have-played
[C++] Convert to Minutes Since Zero Hundred Hours Juliett (0000), O(1) Runtime, O(1) Memory
c-convert-to-minutes-since-zero-hundred-v5a76
\nclass Solution {\npublic:\n int numberOfRounds(string in, string out) {\n int login = ((in[0] - \'0\') * 10 + (in[1] - \'0\')) * 60 + (in[3] - \'0\'
amanmehara
NORMAL
2024-05-13T04:25:02.824271+00:00
2024-05-13T05:28:19.390354+00:00
7
false
```\nclass Solution {\npublic:\n int numberOfRounds(string in, string out) {\n int login = ((in[0] - \'0\') * 10 + (in[1] - \'0\')) * 60 + (in[3] - \'0\') * 10 + (in[4] - \'0\');\n int logout = ((out[0] - \'0\') * 10 + (out[1] - \'0\')) * 60 + (out[3] - \'0\') * 10 + (out[4] - \'0\');\n if (logout < login) {\n logout += 24 * 60;\n }\n return max(0, (logout / 15) - (login / 15) - (login % 15 != 0));\n }\n};\n```
0
0
['Math', 'String', 'C++']
0
the-number-of-full-rounds-you-have-played
Beats 100% || Simple Taught
beats-100-simple-taught-by-velox-god-4yg6
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n-
VELOX-GOD
NORMAL
2024-04-19T13:40:13.079172+00:00
2024-04-19T13:40:13.079205+00:00
16
false
![Screenshot (156).png](https://assets.leetcode.com/users/images/534a8b02-27fb-47d7-8319-30c10f49e592_1713533992.7405508.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public static int fn(int y,int x){\n int sum=0;\n while(y!=x){\n sum+=4;\n ++y;\n if(y==24)\n y=0;\n }\n return sum;\n }\n public int numberOfRounds(String li, String lo) {\n int y=Integer.parseInt(li.substring(0,2));\n int x=Integer.parseInt(lo.substring(0,2));\n int sum=0;\n sum=fn(y,x);\n int yy=Integer.parseInt(li.substring(3,5));\n int xx=Integer.parseInt(lo.substring(3,5));\n if(x==y && xx<yy)\n sum=96;\n if(yy!=0)\n if(yy<=15)\n --sum;\n else if(yy<=30)\n sum-=2;\n else if(yy<=45)\n sum-=3;\n else\n sum-=4;\n if(xx!=0)\n if(xx>=45)\n sum+=3;\n else if(xx>=30)\n sum+=2;\n else if(xx>=15)\n sum+=1;\n return Math.max(0,sum);\n }\n}\n```
0
0
['String', 'Java']
0
minimum-number-of-people-to-teach
Python, 3 steps
python-3-steps-by-warmr0bot-cs9m
First, find those who can\'t communicate with each other.\nThen, find the most popular language among them.\nThen teach that language to the minority who doesn\
warmr0bot
NORMAL
2021-01-23T16:03:25.260377+00:00
2021-01-23T16:06:00.408004+00:00
5,246
false
First, find those who can\'t communicate with each other.\nThen, find the most popular language among them.\nThen teach that language to the minority who doesn\'t speak it: \n```\ndef minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n\tlanguages = [set(l) for l in languages]\n\n\tdontspeak = set()\n\tfor u, v in friendships:\n\t\tu = u-1\n\t\tv = v-1\n\t\tif languages[u] & languages[v]: continue\n\t\tdontspeak.add(u)\n\t\tdontspeak.add(v)\n\n\tlangcount = Counter()\n\tfor f in dontspeak:\n\t\tfor l in languages[f]:\n\t\t\tlangcount[l] += 1\n\n\treturn 0 if not dontspeak else len(dontspeak) - max(list(langcount.values()))\n```
98
0
['Python', 'Python3']
30
minimum-number-of-people-to-teach
Java O(M*N) Solution
java-omn-solution-by-kelvinchandra1024-bx7i
Find out all friendships that already possible w/o any teaching\n- the rest we try to teach using 1 language, find out from all language, what is the minimum we
kelvinchandra1024
NORMAL
2021-01-23T16:07:23.429598+00:00
2021-01-23T17:10:46.380094+00:00
2,963
false
- Find out all friendships that already possible w/o any teaching\n- the rest we try to teach using 1 language, find out from all language, what is the minimum we need to teach\n```\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n Map<Integer, Set<Integer>> languagesMap = new HashMap<>();\n for(int i = 0; i < languages.length; i++) {\n languagesMap.put(i + 1, new HashSet<>());\n for(int l : languages[i]) {\n languagesMap.get(i + 1).add(l);\n }\n }\n boolean[] alreadyCan = new boolean[friendships.length];\n for(int j = 1; j <= n; j++) {\n for(int i = 0; i < friendships.length; i++) {\n if(languagesMap.get(friendships[i][0]).contains(j) && languagesMap.get(friendships[i][1]).contains(j)) {\n alreadyCan[i] = true;\n }\n } \n }\n int minTeach = Integer.MAX_VALUE;\n for(int i = 1; i <= n; i++) {\n Set<Integer> teachSet = new HashSet<>();\n for(int j = 0; j < friendships.length; j++) {\n if(alreadyCan[j]) continue;\n if(!languagesMap.get(friendships[j][0]).contains(i)) teachSet.add(friendships[j][0]);\n if(!languagesMap.get(friendships[j][1]).contains(i)) teachSet.add(friendships[j][1]);\n }\n minTeach = Math.min(teachSet.size(), minTeach);\n }\n return minTeach;\n }\n}\n```
29
3
[]
5
minimum-number-of-people-to-teach
[C++] Explanation and code
c-explanation-and-code-by-shivankacct-xae7
The key idea is to try each language one by one, since we are only allowed to use one language\n* Then iterate over each friendship. \n * If the two friends ca
shivankacct
NORMAL
2021-01-23T16:08:05.647218+00:00
2021-01-23T16:15:03.997233+00:00
2,389
false
* The key idea is to try each language one by one, since we are only allowed to use one language\n* Then iterate over each friendship. \n * If the two friends can already communicate via a common language, ignore and move to next friendship\n * Otherwise, teach them the language (assuming they don\'t know it already)\n * Find the minimum number of friends to teach for any language\n\n```\nclass Solution {\npublic:\n\n\t// Memoize results since the same query is asked repeatedly\n\tvector<vector<int>> mem; \t\n\t\n\t// Check to see if u and v already speak a common language\n bool check(vector<vector<int>>& a, int u, int v) {\n if(mem[u][v] != 0) return mem[u][v] == 1;\n for(int i=0; i<a[v].size(); i++) {\n if(find(a[u].begin(), a[u].end(), a[v][i]) != a[u].end()) {\n mem[v][u] = mem[u][v] = 1;\n return true;\n }\n }\n mem[u][v] = mem[v][u] = -1;\n return false;\n }\n\t\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m = languages.size(), ret = m, i;\n mem.assign(m + 1, vector<int>(m + 1, 0));\n\t\t\n for(i=0; i<m; i++)\n sort(languages[i].begin(), languages[i].end()); \t\t// May not be necessary, just a precaution\n\t\t\t\n for(int lang=1; lang<=n; lang++) {\n int count = 0;\n vector<bool> teach(m, false);\n for(i=0; i<friendships.size(); i++) {\n int u = friendships[i][0] - 1;\n int v = friendships[i][1] - 1;\n if(check(languages, u, v)) \n continue;\n if(find(languages[u].begin(), languages[u].end(), lang) == languages[u].end()) {\n if(!teach[u])\n count++;\n teach[u] = true;\n }\n if(find(languages[v].begin(), languages[v].end(), lang) == languages[v].end()) {\n if(!teach[v])\n count++;\n teach[v] = true;\n }\n }\n ret = min(ret, count);\n }\n return ret;\n }\n};\n```
10
0
[]
3
minimum-number-of-people-to-teach
Python 3 || 5 lines, w/ explanation and example || T/S: 95% / 45%
python-3-5-lines-w-explanation-and-examp-zst6
Here\'s the plan:\n- Determine the group of users who do not have a common language with at least one friend.\n- Determine the most common language in that grou
Spaulding_
NORMAL
2023-02-22T22:48:53.599131+00:00
2024-06-06T23:14:26.342736+00:00
783
false
Here\'s the plan:\n- Determine the group of users who do not have a common language with at least one friend.\n- Determine the most common language in that group.\n- Return the number in the group who do not speak that language.\n```\nclass Solution:\n def minimumTeachings(self, n, languages, friendships):\n # Example:\n l = list(map(set,languages)) # friendships = [[1,4],[1,2],[3,4],[2,3]]\n # languages = [[2] ,[1,3],[1,2],[1,3]]\n users = set(chain(*((i-1,j-1) for i,j in \n friendships if not l[i-1]&l[j-1]))) # users = {0,1,3} <- zero-indexed\n\n if not users: return 0\n\n ctr = Counter(chain(*[languages[i] for i in users])) # ctr = {1:2, 3:2, 2:1}\n \n return len(users) - max(ctr.values()) # return len({0,1,3}) - max(2,2,1) = 3 - 2 = 1\n```\n[https://leetcode.com/problems/minimum-number-of-people-to-teach/submissions/1280009930/](https://leetcode.com/problems/minimum-number-of-people-to-teach/submissions/1280009930/)\n\n\n\nI could be wrong, but I think that time complexity is *O*(*M* + *N*) and space complexity is *O*(*M* + *N*).\n
9
0
['Python3']
0
minimum-number-of-people-to-teach
[Python3] Simple | With Comments
python3-simple-with-comments-by-sushanth-n20r
\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n ans = inf\n language
sushanthsamala
NORMAL
2021-01-23T16:01:25.897609+00:00
2021-01-23T16:06:59.877468+00:00
1,117
false
```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n ans = inf\n languages = [set(x) for x in languages]\n \n for language in range(1, n+1):\n curr, seen = 0, set()\n \n for a,b in friendships:\n if len(languages[a-1] & languages[b-1]) == 0: # if no common languaes i.e, friends cannot communicate\n \n if language not in languages[a-1] and a not in seen:\n curr += 1\n seen.add(a)\n if language not in languages[b-1] and b not in seen:\n curr += 1\n seen.add(b)\n \n if curr >= ans: break # Early break condition \n \n ans = min(ans, curr)\n return ans\n```
9
0
[]
3
minimum-number-of-people-to-teach
Java simple solution
java-simple-solution-by-nileshr-p68r
\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n\n // record the languages known to every user\n Map<I
nileshr
NORMAL
2021-01-23T16:00:58.643924+00:00
2021-01-23T16:04:08.951647+00:00
1,341
false
```\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n\n // record the languages known to every user\n Map<Integer,Set<Integer>> ul = new HashMap<>();\n for(int i=0; i<languages.length; i++) {\n Set<Integer> lang = new HashSet<>();\n ul.put(i+1, lang);\n for(int l : languages[i]) {\n lang.add(l);\n }\n }\n\n // if two users are friends and they can\'t speak to each other due to language issue, record it\n Map<Integer,Set<Integer>> uf = new HashMap<>();\n for(int i=0; i<friendships.length; i++) {\n int[] frnd = friendships[i];\n boolean canSpk = false;\n for(int l : ul.get(frnd[0])) {\n if(ul.get(frnd[1]).contains(l)) {\n canSpk = true;\n break;\n }\n }\n if(canSpk) continue;\n \n uf.putIfAbsent(frnd[0],new HashSet<>());\n uf.putIfAbsent(frnd[1],new HashSet<>());\n uf.get(frnd[0]).add(frnd[1]);\n uf.get(frnd[1]).add(frnd[0]);\n }\n \n int ans = Integer.MAX_VALUE;\n // for every language, see how many users need to learn it\n for(int i=1; i<=n; i++) {\n int tot = 0;\n // if we have to teach language i, then how many users need to learn this?\n for(int key : uf.keySet()) {\n if(!ul.get(key).contains(i)) tot++;\n }\n // if this language needs to be learned by less number of people, then this is the answer, else don\'t override the ans\n ans = Math.min(ans, tot);\n }\n \n return ans;\n }\n}\n\n\n```
9
0
[]
2
minimum-number-of-people-to-teach
Fast Solution - Four Lines of Code
fast-solution-four-lines-of-code-by-mikp-a5ji
Code #1\nTime complexity: O(fn + mn). Space complexity: O(mn). f - number of friendships, m - users, n - languages\n\nclass Solution:\n def minimumTeachings(
MikPosp
NORMAL
2023-12-27T11:43:33.496371+00:00
2024-11-08T11:41:33.091681+00:00
148
false
# Code #1\nTime complexity: $$O(f*n + m*n)$$. Space complexity: $$O(m*n)$$. f - number of friendships, m - users, n - languages\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n userToLang = {u:{*langs} for u,langs in enumerate(languages, 1)}\n muteUsers = {u for f in friendships if not userToLang[f[0]]&userToLang[f[1]] for u in f}\n langCntr = Counter(lang for u in muteUsers for lang in userToLang[u])\n\n return len(muteUsers) - (langCntr and langCntr.most_common(1)[0][1] or 0)\n```\n\n# Code #2\nTime complexity: $$O(f*n + m*n)$$. Space complexity: $$O(m*n+f)$$. f - number of friendships, m - users, n - languages\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n userToLang = {u:{*langs} for u,langs in enumerate(languages, 1)}\n friendships = [f for f in friendships if not userToLang[f[0]]&userToLang[f[1]]]\n if not friendships: return 0\n\n return min(len({u for f in friendships for u in f if l not in userToLang[u]}) for l in range(1,n+1))\n```
8
0
['Array', 'Hash Table', 'Counting', 'Python', 'Python3']
0
minimum-number-of-people-to-teach
Intiution & Explanation with code & comments, beats 100% C++
intiution-explanation-with-code-comments-n5n2
To find the language to be taught to minimum number of people in real life, we can call the number of people who cant communicate with atleast one of their frie
parth2510
NORMAL
2021-01-23T21:00:18.656714+00:00
2021-01-23T21:00:18.656774+00:00
1,030
false
To find the language to be taught to minimum number of people in real life, we can call the number of people who cant communicate with atleast one of their friend and of all of them can vote what is the most popular language among them, and those who dont know (minority) will learn it\n```\nclass Solution {\npublic:\n bool checkinvalid( int a, int b, vector<vector<int>>& languages){ //helper func., checks if a and b can communicate or not\n a--; b--;\n for( int i=0;i<languages[a].size();i++){\n if(find(languages[b].begin(), languages[b].end(), languages[a][i]) != languages[b].end()) return false;\n }\n return true;\n }\n \n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) { \n int m= languages.size();\n vector<vector<int>> g(m+1, vector<int>(0)); // graph to store adjacency list with people as nodes & friendships as edges\n // create graph\n for( int i=0;i<friendships.size();i++){\n g[friendships[i][0]].push_back(friendships[i][1]);\n g[friendships[i][1]].push_back(friendships[i][0]);\n }\n \n vector<int> voters(m+1,0); // to store people who cant communicate with atleast a friend\n int voterscount=0; \n for( int i=1;i<m+1;i++){\n for( int j=0;j<g[i].size();j++){\n if( checkinvalid(i, g[i][j], languages)){ // ith can vote\n voters[i]=1;\n voterscount++;\n break;\n }\n }\n }\n unordered_map<int,int> mappy; // language -> votes\n int maxvotes=0; \n \n for( int i=1;i<m+1;i++){\n if(voters[i]==1){ \n for( int j: languages[i-1]){\n mappy[j]++;\n \n if(maxvotes<mappy[j]){\n maxvotes= mappy[j];\n }\n }\n }\n }\n return voterscount - maxvotes; // # who need to be taught the language\n }\n};\n```\n
8
1
['C']
0
minimum-number-of-people-to-teach
c++ easy solution using hashmap
c-easy-solution-using-hashmap-by-samiksh-bv61
\nclass Solution {\npublic:\n bool intersection(vector<int>a,vector<int>b){\n for(int i=0;i<a.size();i++){\n for(int j=0;j<b.size();j++){\n
samiksha_1405
NORMAL
2021-01-24T11:45:49.457185+00:00
2021-01-24T11:45:49.457227+00:00
1,472
false
```\nclass Solution {\npublic:\n bool intersection(vector<int>a,vector<int>b){\n for(int i=0;i<a.size();i++){\n for(int j=0;j<b.size();j++){\n \n if(a[i]==b[j])return true;\n }\n \n }\n return false;\n }\n \n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n unordered_map<int,vector<int>>ump;\n int l=languages.size();\n int f=friendships.size();\n set<int>s;\n for(int i=0;i<f;i++){\n \n if(!intersection(languages[friendships[i][0]-1],languages[friendships[i][1]-1])){\n \n s.insert(friendships[i][0]);\n s.insert(friendships[i][1]);\n }\n }\n \n \n for(int j=0;j<l;j++){\n if(s.find(j+1)==s.end()) continue;\n for(int k=0;k<languages[j].size();k++){\n ump[languages[j][k]].push_back(j+1);\n }\n }\n \n int ans=0;\n for(int i=1;i<=ump.size();i++){\n if(ans<ump[i].size())ans=ump[i].size();\n }\n \n return s.size()-ans;\n \n \n }\n};\n```
4
0
['C', 'Ordered Set', 'C++']
2
minimum-number-of-people-to-teach
C++ hash table solution with explanation and comments
c-hash-table-solution-with-explanation-a-xaso
Idea:\n1. Check if there isn\'t common language for a friendship pair, then at least 1 person of the pair must be taught\n2. Count the number of such people (eg
eminem18753
NORMAL
2021-01-24T03:05:38.829562+00:00
2021-01-24T03:24:50.184830+00:00
167
false
Idea:\n1. Check if there isn\'t common language for a friendship pair, then at least 1 person of the pair must be taught\n2. Count the number of such people (eg. those may need to be taught) who know a certain language and store them in a map\n-> mapping language to number of people who know it\n3. We can get the minimum number of people who need to be taught\n```\nclass Solution \n{\n public:\n bool check(vector<int>& a,vector<int>& b)\n {\n\t\t//to check if a and b has common language (with 2 pointer)\n int m=a.size(),n=b.size(),p1=0,p2=0;\n while(p1<m&&p2<n)\n {\n if(a[p1]<b[p2]) p1++;\n else if(a[p1]>b[p2]) p2++;\n else return true;\n }\n return false;\n }\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) \n {\n int m=languages.size(),t=friendships.size();\n unordered_set<int> total;\n unordered_map<int,int> overall;\n for(int i=0;i<m;i++)\n sort(languages[i].begin(),languages[i].end()); //in order to use 2 pointers to check common language later\n\n for(int i=0;i<t;i++)\n if(!check(languages[friendships[i][0]-1],languages[friendships[i][1]-1])) //no common language\n total.insert(friendships[i][0]),total.insert(friendships[i][1]); //at least 1 of the person must be taught\n\n int s=total.size(),result=s; //total number of people who might need to be taught\n \n for(unordered_set<int>::iterator it=total.begin();it!=total.end();it++)\n {\n vector<int>& language=languages[*it-1];\n for(int i=0;i<language.size();i++) //all languages that current people know\n overall[language[i]]++; //mapping language to number of people who know it\n }\n for(unordered_map<int,int>::iterator it=overall.begin();it!=overall.end();it++)\n result=min(result,s-it->second); //get the minimum number of people who need to be taught\n\t\t\t\n return result;\n }\n};\n```
4
0
[]
0
minimum-number-of-people-to-teach
[c++ 200ms 100%] bitset
c-200ms-100-bitset-by-summerzhou-u910
1 Use bitset to represent the languages of a user (bitset is very similar to a mask)\n2 Use bitset to test if two users has common langue, if not, we mark th
summerzhou
NORMAL
2021-01-24T01:02:00.226053+00:00
2021-01-24T01:18:00.193925+00:00
334
false
1 Use bitset to represent the languages of a user (bitset is very similar to a mask)\n2 Use bitset to test if two users has common langue, if not, we mark the two user as candidate ( has at least one friend he can not talk to). \n Here we want to exclude all users that have no issue to talk to his/her friends.\n3 For all users candidate, we caculate the usage count of each language. \n\n4 The answer is min(users candidate count - usage count of one language). \n In another way, among all users involved, the language used by most user candidates is the language we choose.\n \n\nTime : m * n\n\n```\nclass Solution {\npublic:\n int n;\n int m;\n vector<bitset<501>> dp;\n int minimumTeachings(int n1, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n n = n1;\n m = languages.size();\n dp.resize(m + 1);\n for (int i =0; i < m; i++)\n {\n for (auto& l : languages[i])\n {\n dp[i + 1][l] = 1;\n }\n }\n \n vector<int> candicate(m + 1, 0);\n for (auto& v : friendships)\n {\n bitset<501> un = dp[v[0]] & dp[v[1]];\n if (un.count() == 0)\n {\n //nospeakfrieds.push_back(v);\n candicate[v[0]] = 1;\n candicate[v[1]] = 1;\n }\n }\n vector<int> ldp(n + 1, 0);\n int cnt = 0;\n for (int i = 1; i <= m; i++)\n {\n if (candicate[i] == 1)\n {\n cnt++;\n for (auto& l : languages[i-1])\n {\n ldp[l]++;\n }\n }\n }\n int res = cnt;\n //cout << cnt << endl;\n for (int i = 1; i <= n; i++)\n {\n //cout << i << "," << ldp[i] << endl;\n res = min(res, cnt - ldp[i]);\n }\n return res;\n }\n};\n```
4
0
[]
1
minimum-number-of-people-to-teach
[Python3] Faster than 100% submissions in time and memory, detailed explanation step by step,
python3-faster-than-100-submissions-in-t-skz9
\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n """\n 1. Find out us
shot58
NORMAL
2021-01-23T17:58:18.804249+00:00
2021-01-24T08:52:24.272722+00:00
436
false
```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n """\n 1. Find out users who need to be taught\n 2. If no user needs to be taught, return 0\n 3. For all users who need to be taught a language, find the most popular language among them\n 4. Teach that language to rest of the users who need to be taught. \n """\n need_to_be_taught = set()\n languages = [set(language) for language in languages]\n \n # 1. Find out users who needs to be taught\n for user1, user2 in friendships:\n # Adjust the 1 based indexing to 0 based indexing\n user1 = user1 - 1\n user2 = user2 - 1\n if not (languages[user1] & languages[user2]):\n need_to_be_taught.update([user1, user2])\n \n # 2. If no user needs to be taught, return 0\n if not need_to_be_taught:\n return 0\n \n # 3. For all users who needs to be taught a language, find the most popular language among them\n language_spoken_by = collections.defaultdict(int)\n for user in need_to_be_taught:\n # for each user increment the count of languages he can speak\n for language in languages[user]:\n language_spoken_by[language] += 1\n \n # find occurrence of language spoken by maximum users who can\'t communicate with each other\n popular_language_count = max(language_spoken_by.values())\n \n # 4. Teach that language to rest of the users who need to be taught. \n return len(need_to_be_taught)- popular_language_count\n \n \n \n \n```
4
0
['Ordered Set', 'Python', 'Python3']
1
minimum-number-of-people-to-teach
C++ greedy simulate
c-greedy-simulate-by-navysealsniper-pw2v
\n\n int minimumTeachings(int n, vector>& languages, vector>& friendships) {\n \n\t\t\n\t\t// we save each users language id list into map, with id as
navysealsniper
NORMAL
2021-01-23T16:49:06.556363+00:00
2021-01-23T18:36:21.486655+00:00
593
false
\n\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n \n\t\t\n\t\t// we save each users language id list into map, with id as key\n std::map<int, set<int>> users;\n for(int i = 0; i < languages.size(); ++i) {\n for(auto& l : languages[i]) {\n users[i + 1].insert(l);\n }\n }\n \n\t\t// then we go through each relationship\n\t\t// if a pair of friend don\'t have common language\n\t\t// we save their language and user id into set\n\t\t// we can prove, target language must chosen from lang set\n set<int> lang;\n set<int> people;\n for(auto& f : friendships) {\n \n bool skip = false; // if they have one common language, skip is true\n for(auto& l : users[f[0]]) {\n if (users[f[1]].count(l) > 0) {\n skip = true;\n break;\n }\n }\n \n if (!skip) {\n for(auto& l : users[f[0]]) { // save user a\'s language into set\n lang.insert(l);\n }\n for(auto& l : users[f[1]]) { // save user b\'s language into set\n lang.insert(l);\n }\n \n\t\t\t\t// at the same time, save user a and b into people set\n people.insert(f[0]);\n people.insert(f[1]);\n }\n }\n int res = lang.empty() ? 0 : languages.size(); // if no pair of relationship has no common language, the result is 0;\n \n\t\t\n\t\t// chose any fron lang set, and calculate how many people need taught\n\t\t// save the minimum as result\n for(auto& l : lang) {\n int cnt = 0;\n for(auto& p : people) {\n if (users[p].count(l) == 0) {\n ++cnt;\n }\n }\n res = std::min(res, cnt);\n }\n \n return res;\n \n }
4
0
[]
2
minimum-number-of-people-to-teach
Java Accepted Solution
java-accepted-solution-by-vikrant_pc-gxn5
\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n int result = languages.length;\n List<Set<I
vikrant_pc
NORMAL
2021-01-23T16:02:24.030121+00:00
2021-01-23T16:17:04.087497+00:00
540
false
```\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n int result = languages.length;\n List<Set<Integer>> langList = new ArrayList<>();\n for(int[] userLangs: languages) {\n Set<Integer> langSet = new HashSet<>();\n for(int userLang : userLangs) langSet.add(userLang);\n langList.add(langSet);\n }\n List<int[]> fs = new ArrayList<>();\n for(int[] friendship : friendships) \n if(noCommonLang(langList.get(friendship[0]-1), langList.get(friendship[1]-1)))\n fs.add(friendship);\n for(int lang=1;lang<=n;lang++) {\n Set<Integer> usersUpdated = new HashSet<>();\n for(int[] friendship : fs) {\n if(!langList.get(friendship[0] - 1).contains(lang)) {\n langList.get(friendship[0] - 1).add(lang);\n usersUpdated.add(friendship[0]-1);\n }\n if(!langList.get(friendship[1] - 1).contains(lang)) {\n langList.get(friendship[1] - 1).add(lang);\n usersUpdated.add(friendship[1]-1);\n }\n }\n result = Math.min(result, usersUpdated.size());\n for(int user: usersUpdated) \n langList.get(user).remove(lang);\n }\n return result;\n }\n private boolean noCommonLang(Set<Integer> set1, Set<Integer> set2) {\n if(set2.size() < set1.size()) {\n for(int i:set2)\n if(set1.contains(i)) return false;\n } else { \n for(int i:set1) \n if(set2.contains(i)) return false;\n }\n return true;\n }\n}\n```
4
1
[]
0
minimum-number-of-people-to-teach
Java detailed solution . Properly documented
java-detailed-solution-properly-document-s1lk
\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n //This is the language map . Key is the person , T
noobpotatocoder
NORMAL
2021-01-29T15:50:06.892848+00:00
2021-01-29T15:50:06.892898+00:00
450
false
```\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n //This is the language map . Key is the person , The hashSet is the languages he can speak. We use a hashset to optimize the searching\n HashMap<Integer,HashSet<Integer>> languageMap = new HashMap<>();\n \n //We put the languages known to a map\n for(int i=0;i<languages.length;i++){\n \n languageMap.put(i+1,new HashSet<>());\n \n for(int l : languages[i])\n languageMap.get(i+1).add(l);\n \n }\n \n //THis is the length of languages matrix\n int ans = languages.length;\n \n //For each language we count the minimum no of people whom we need to teach a particular language i\n for(int i=1;i<=n;i++){\n ans = Math.min(ans,num_of_users_to_teach(i,friendships,languageMap));\n }\n \n //The minimum no of people is returned\n return ans;\n \n \n \n }\n //This method counts the minimum no of people to teach a given language lang so that all of them can communicate.\n private int num_of_users_to_teach(int lang,int[][] friendships, HashMap<Integer,HashSet<Integer>> languageMap){\n \n //We put the unique no of people whom we need to teach languages\n HashSet<Integer> temp = new HashSet<>();\n \n for(int i=0;i<friendships.length;i++){\n //first and second refers to two persons forming a friendship\n int first = friendships[i][0];\n int second = friendships[i][1];\n //languages spoken by the first user\n HashSet<Integer> lang_first = languageMap.get(first);\n //Languages spoken by the second user\n HashSet<Integer> lang_second = languageMap.get(second);\n \n //We first check whether they can communicate which adding this language lang.\n if(!isCommon(lang_first,lang_second)){\n //If the language lang is not present in the first persons vocabulary we add it.\n if(!lang_first.contains(lang))\n temp.add(first);\n //If the language lang is not present in the second persons vocabulary we add it.\n if(!lang_second.contains(lang))\n temp.add(second);\n \n }\n \n \n \n }\n \n return temp.size();\n \n \n }\n \n //This method checks whether the communication between two person is possible or not .\n private boolean isCommon(HashSet<Integer> first,HashSet<Integer> second){\n \n for(int k : first){\n if(second.contains(k))\n return true;\n }\n return false;\n \n \n }\n \n \n}\n```
3
1
['Java']
0
minimum-number-of-people-to-teach
Java Concise BitSet 98% | Problem Explanation
java-concise-bitset-98-problem-explanati-dn2r
Let\'s say we have an interger of 500 bits, then we can set the bit for each person for the language they speak, so if person A speaks langage 1 and 4 out of 4
Student2091
NORMAL
2022-05-05T23:35:08.356490+00:00
2022-05-05T23:35:08.356540+00:00
273
false
Let\'s say we have an interger of 500 bits, then we can set the bit for each person for the language they speak, so if person A speaks langage 1 and 4 out of 4 language, it\'d be represented as `0b1001`. We can then just `&` it with another person\'s number to find out if they share a common language.\n\nThe issue here is that we don\'t have a 500-bit integer, but we do have a bitset class which can represent that and has all the bitwise operation built-in, so let\'s use that.\n\n**THIS QUESTION IS VERY CONFUSING**. I spent 3 hrs just to understand what was being asked. You are **ONLY** allowed to teach `1` language to EVERYBODY. \nTake this test case for example:\n```\n4\n[[1],[2],[3],[4]]\n[[1,2],[3,4]]\n```\nOne may intuitively think that the answer should be 2 because we can teach person 1 the 2nd language and person 3 the 4th language; However that\'s against the rule because we are only allowed to teach **exactly** 1 language. Because we are only allowed to teach 1 language, we should teach the language that are most common so as to reduce the number of user that needs to be taught. \n\n**Java (98% Speed):**\n\n```Java\nclass Solution {\n public int minimumTeachings(int n, int[][] L, int[][] F) {\n BitSet[] bit = new BitSet[L.length];\n Arrays.setAll(bit, o -> new BitSet(n + 1));\n for (int i = 0; i < L.length; i++){\n for (int l : L[i]){\n bit[i].set(l);\n }\n }\n Set<Integer> teach = new HashSet<>();\n for (int[] f : F){\n BitSet t = (BitSet)bit[f[0] - 1].clone();\n t.and(bit[f[1] - 1]);\n if (t.isEmpty()){\n teach.add(f[0] - 1);\n teach.add(f[1] - 1);\n }\n }\n int[] count = new int[n + 1];\n for (int person : teach){\n for (int l : L[person]){\n count[l]++;\n }\n }\n\n return teach.size() - Arrays.stream(count).max().getAsInt();\n }\n}\n```
2
0
['Java']
0
minimum-number-of-people-to-teach
Python 3, Greedy, 95% time
python-3-greedy-95-time-by-huangshan01-4wb1
\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n # For all friends who canno
huangshan01
NORMAL
2021-11-29T05:22:33.966483+00:00
2021-11-30T04:40:05.548958+00:00
244
false
```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n # For all friends who cannot chat, find out the most common language they speak\n # Then teach the language to those unable to speak it, and return how many being taught\n \n friendships = [(u-1, v-1) for u, v in friendships] # convert to indices\n ls = [set(l) for l in languages] # make sets\n visited = set()\n ct = Counter()\n \n for u, v in friendships:\n if not (ls[u] & ls[v]):\n if u not in visited:\n visited.add(u)\n for l in ls[u]:\n ct[l] += 1\n if v not in visited:\n visited.add(v)\n for l in ls[v]:\n ct[l] += 1\n if not ct:\n return 0\n \n # The most common language among all friends who cannot communicate\n target = sorted(list(ct.items()), key = lambda x: x[1])[-1][0]\n \n ans = 0\n for x in visited: # among all friends unable to chat\n if target not in ls[x]: # if x doesnt speak target, teach it to x\n ans += 1\n return ans\n```
2
0
['Greedy']
0
minimum-number-of-people-to-teach
C++ || Map
c-map-by-aparna_g-upyd
\nclass Solution {\npublic:\n bool findCommon(vector<int>&a, vector<int>&b) {\n for(int i=0;i<a.size();i++) {\n for(int j=0;j<b.size();j++)
aparna_g
NORMAL
2021-06-21T12:35:25.780529+00:00
2021-06-21T12:35:25.780564+00:00
404
false
```\nclass Solution {\npublic:\n bool findCommon(vector<int>&a, vector<int>&b) {\n for(int i=0;i<a.size();i++) {\n for(int j=0;j<b.size();j++) {\n if(a[i]==b[j])\n return 1;\n }\n }\n return 0;\n }\n \n int minimumTeachings(int n, vector<vector<int>>& lang, vector<vector<int>>& friends) {\n int l = lang.size();\n int f = friends.size();\n set<int> ppl_with_no_common; \n unordered_map<int,vector<int>> mp ; \n //language , array of users\n \n for(int i=0;i<f;i++) {\n if(!findCommon(lang[friends[i][0]-1] , lang[friends[i][1]-1])) //if friends cannot communiate with each other\n {\n ppl_with_no_common.insert(friends[i][0]);\n ppl_with_no_common.insert(friends[i][1]);\n }\n }\n \n for(int j=0;j<l;j++) {\n if(ppl_with_no_common.find(j+1)!=ppl_with_no_common.end()) {\n for(int k=0;k<lang[j].size();k++) \n mp[lang[j][k]].push_back(j+1);\n }\n }\n int ans = 0;\n int language = 0;\n for(int i=1;i<=mp.size();i++) {\n if(ans<mp[i].size()) {\n ans = mp[i].size();\n language = i;\n }\n }\n // ans denotes the number of people speaking the most common language. \n // so teach this language \'l\' to the people who cannot communicate with their friends.\n // cout<<language<<" will be taught to " << ppl_with_no_common.size()-ans <<" people!";\n return ppl_with_no_common.size()-ans;\n }\n};\n```
2
0
['C', 'C++']
0
minimum-number-of-people-to-teach
DSU rejected why?
dsu-rejected-why-by-siddharthraja9849-r6li
Can someone please guide me with this?\nI tried to detect cycle in the graph and then get most popular language amongst them.\nThen summition of abs(totalSizeOf
siddharthraja9849
NORMAL
2021-01-23T16:12:25.432703+00:00
2021-01-23T16:12:25.432745+00:00
258
false
Can someone please guide me with this?\nI tried to detect cycle in the graph and then get most popular language amongst them.\nThen summition of abs(totalSizeOfConnectedComponents-frequencyOfUserKnowing a langauage) gives me answer\n```\n\n#define REP(i,a,b) for(int i=a;i<b;i++)\n\nclass Solution {\npublic:\n \n typedef struct node{\n set<int>allNodes;\n struct node *next;\n }node;\n \n unordered_map<int,struct node *>dic;\n unordered_map<struct node *,bool>parentDic;\n \n void init(int x){\n node *newNode=new node;\n newNode->next=NULL;\n newNode->allNodes.insert(x);\n dic[x]=newNode;\n \n parentDic[newNode]=true;\n //cout<<newNode<<endl;\n }\n \n node *parent(int d){\n node *p=dic[d];\n cout<<"p :"<<p<<endl;\n while(p->next!=NULL)p=p->next;\n node *q=dic[d];\n while(q->next!=p&&q->next!=NULL){\n node *t=q->next;\n q->next=p;\n q=t;\n }\n cout<<p<<endl;\n return p;\n }\n \n void merge(int a,int b){\n \n node *parentA=parent(a);\n node *parentB=parent(b);\n \n if(parentA!=parentB){\n \n parentA->next=parentB;\n \n for(auto ele:parentA->allNodes){\n cout<<"inserting :"<<ele<<endl;\n parentB->allNodes.insert(ele);\n }\n \n parentDic[parentA]=false;\n parentDic[parentB]=true;\n \n }\n \n }\n \n \n \n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n \n int users=languages.size();\n int i;\n REP(i,0,users){\n init(i);\n }\n \n for(auto ele:friendships){\n int s=ele[0];\n int d=ele[1];\n s--;\n d--;\n merge(s,d);\n }\n \n int sum=0;\n for(auto ele:parentDic){\n if(ele.second==true){\n \n unordered_map<int,int>mostLang;\n \n int size=ele.first->allNodes.size();\n \n if(size>1){\n for(auto every:ele.first->allNodes){\n for(auto eachLan:languages[every]){\n mostLang[eachLan]++;\n }\n }\n \n int mini=0;\n \n for(auto evry:mostLang){\n mini=max(mini,evry.second);\n }\n \n sum+=abs(mini-size);\n \n \n }\n \n \n }\n }\n \n return sum;\n \n }\n};\n\n\n```
2
1
[]
1
minimum-number-of-people-to-teach
Python3 solution
python3-solution-by-mnikitin-h9qi
\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n friends2commute = []\n
mnikitin
NORMAL
2021-01-23T16:01:28.712642+00:00
2021-01-23T16:01:28.712679+00:00
235
false
```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n friends2commute = []\n for f1, f2 in friendships:\n if not list(set(languages[f1 - 1]) & set(languages[f2 - 1])):\n friends2commute.append([f1, f2])\n if not friends2commute:\n return 0\n\n min_students = float(\'inf\')\n for lang in range(1, n + 1):\n cur_students = 0\n already_know = set()\n for f1, f2 in friends2commute:\n if lang not in languages[f1 - 1] and f1 not in already_know:\n cur_students += 1\n already_know.add(f1)\n if lang not in languages[f2 - 1] and f2 not in already_know:\n cur_students += 1\n already_know.add(f2)\n min_students = min(min_students, cur_students)\n return min_students\n```\n
2
0
[]
0
minimum-number-of-people-to-teach
O(en) time, O(v + n) space
oen-time-ov-n-space-by-isaachaseley-3nim
Approach\n1. Find the friends who aren\'t able to communicate with someone\n2. Find the most common language among them\n3. Teach that to the rest of them \n\n#
isaachaseley
NORMAL
2024-05-19T23:03:41.272472+00:00
2024-05-19T23:03:41.272490+00:00
27
false
# Approach\n1. Find the friends who aren\'t able to communicate with someone\n2. Find the most common language among them\n3. Teach that to the rest of them \n\n# Complexity\n- Time complexity: O(en), where e is the number of edges and n is the number of languages\n\n- Space complexity: O(v + n), where v is the number of vertices and n is the number of languages\n\n# Code\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n students = set()\n for (u, v) in friendships:\n if not set(languages[u - 1]) & set(languages[v - 1]):\n students.add(u)\n students.add(v)\n lang_counts = [0 for _ in range(n + 1)]\n for student in students:\n for lang in languages[student - 1]:\n lang_counts[lang] += 1\n return len(students) - max(lang_counts)\n \n```
1
0
['Python3']
0
minimum-number-of-people-to-teach
[C++] Hash Table, O((M+F)N) Runtime, O(MN) Memory
c-hash-table-omfn-runtime-omn-memory-by-29guo
\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m = languages.size
amanmehara
NORMAL
2024-05-13T09:32:06.570608+00:00
2024-05-13T09:53:19.949276+00:00
154
false
```\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m = languages.size();\n vector<vector<char>> matrix(m + 1, vector<char>(n + 1, false));\n for (int i = 0; i < m; i++) {\n for (const auto& language : languages[i]) {\n matrix[i + 1][language] = true;\n }\n }\n vector<char> learn(m + 1, false);\n for (const auto& friendship : friendships) {\n bool can_communicate = false;\n for (int i = 1; i <= n; i++) {\n if (matrix[friendship[0]][i] && matrix[friendship[1]][i]) {\n can_communicate = true;\n break;\n }\n }\n if (!can_communicate) {\n learn[friendship[0]] = true;\n learn[friendship[1]] = true;\n }\n }\n int minimum_learnings = INT_MAX;\n for (int i = 1; i <= n; i++) {\n int learnings = 0;\n for (int j = 1; j <= m; j++) {\n if (learn[j] && !matrix[j][i]) {\n learnings++;\n }\n }\n minimum_learnings = min(minimum_learnings, learnings);\n }\n return minimum_learnings;\n }\n};\n```
1
0
['Hash Table', 'Greedy', 'C++']
0
minimum-number-of-people-to-teach
JS || Solution by Bharadwaj
js-solution-by-bharadwaj-by-manu-bharadw-bkaq
Code\n\nvar minimumTeachings = function (n, languages, friendships) {\n let mostSpokenLanguages = new Array(n + 1).fill(0);\n let map = new Map();\n\n
Manu-Bharadwaj-BN
NORMAL
2024-02-28T06:58:50.625671+00:00
2024-02-28T06:58:50.625700+00:00
27
false
# Code\n```\nvar minimumTeachings = function (n, languages, friendships) {\n let mostSpokenLanguages = new Array(n + 1).fill(0);\n let map = new Map();\n\n friendships.forEach((element) => {\n let LANG = new Set(languages[element[0] - 1]);\n\n let shareLang = false;\n for (const l of languages[element[1] - 1]) {\n if (LANG.has(l)) {\n shareLang = true;\n break;\n }\n }\n\n if (!shareLang) {\n map.set(element[0], languages[element[0] - 1]);\n map.set(element[1], languages[element[1] - 1]);\n }\n });\n\n map.forEach((value, key) => {\n for (let l of value) ++mostSpokenLanguages[l]\n });\n\n return map.size - Math.max(...mostSpokenLanguages);\n};\n```
1
0
['JavaScript']
1
minimum-number-of-people-to-teach
C++
c-by-avinash_4579-zj8w
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
avinash_4579
NORMAL
2024-01-17T03:36:00.675331+00:00
2024-01-17T03:36:00.675355+00:00
24
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int minimumTeachings(int n,vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m = languages.size();\n vector<unordered_set<int>> langSet(m + 1);\n\n for (int i = 0; i < m; ++i) {\n for (int lang : languages[i]) {\n langSet[i + 1].insert(lang);\n }\n }\n\n vector<pair<int, int>> needLanguage;\n for (const auto& friendship : friendships) {\n int u = friendship[0];\n int v = friendship[1];\n if (!haveCommonLanguage(langSet[u], langSet[v])) {\n needLanguage.push_back({u,v});\n }\n }\n\n if (needLanguage.empty()) {\n return 0;\n }\n\n int minUsers = m;\n for (int lang = 1; lang <= n; ++lang) {\n unordered_set<int> usersToTeach;\n for (const auto& pair : needLanguage) {\n int u = pair.first;\n int v = pair.second;\n if (langSet[u].find(lang) == langSet[u].end()) {\n usersToTeach.insert(u);\n }\n if (langSet[v].find(lang) == langSet[v].end()) {\n usersToTeach.insert(v);\n }\n }\n minUsers = min(minUsers, static_cast<int>(usersToTeach.size()));\n }\n\n return minUsers;\n }\n\nprivate:\n bool haveCommonLanguage(unordered_set<int>& set1,unordered_set<int>& set2) {\n for (int lang : set1) {\n if (set2.count(lang) > 0) {\n return true;\n }\n }\n return false;\n }\n};\n\n```
1
0
['C++']
0
minimum-number-of-people-to-teach
Greedy Solution || O(m*n) || Faster than 60% || Clean code || Java
greedy-solution-omn-faster-than-60-clean-k9zp
Complexity\n- Time complexity: O(mn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(mn)\n Add your space complexity here, e.g. O(n) \n\n#
youssef1998
NORMAL
2023-08-01T20:31:30.669761+00:00
2023-08-01T20:31:30.669787+00:00
390
false
# Complexity\n- Time complexity: $$O(m*n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(m*n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport java.util.*;\nimport java.util.stream.Collectors;\n\nclass Solution {\n private final Map<Integer, Set<Integer>> langToPeople = new HashMap<>();\n private int mostSpoken = -1;\n private int mostSpokenCount = 0;\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n Map<Integer, Set<Integer>> peopleToLanguages = initLanguages(languages); //O(n)\n Set<Map.Entry<Integer,Integer>> cantSpeak = getRelationships(friendships, peopleToLanguages); //o(m*n)\n int learners = 0;\n for (Map.Entry<Integer, Integer> friends: cantSpeak) { //o(m)\n Set<Integer> lang1 = peopleToLanguages.getOrDefault(friends.getKey(), new HashSet<>());\n Set<Integer> lang2 = peopleToLanguages.getOrDefault(friends.getValue(), new HashSet<>());\n learners += learnLanguage(peopleToLanguages, friends.getKey(), lang1);\n learners += learnLanguage(peopleToLanguages, friends.getValue(), lang2);\n }\n return learners;\n }\n\n private Map<Integer, Set<Integer>> initLanguages(int[][] languages) {\n Map<Integer, Set<Integer>> peopleToLanguages = new HashMap<>();\n for (int i = 0; i < languages.length; i++) {\n peopleToLanguages.put(i + 1, Arrays.stream(languages[i]).boxed().collect(Collectors.toSet()));\n }\n return peopleToLanguages;\n }\n\n private Set<Map.Entry<Integer,Integer>> getRelationships(int[][] friendships, Map<Integer, Set<Integer>> peopleToLanguages) {\n Set<Map.Entry<Integer,Integer>> cantSpeak = new HashSet<>();\n for (int[] friendship: friendships) {\n Set<Integer> lang1 = peopleToLanguages.getOrDefault(friendship[0], new HashSet<>());\n Set<Integer> lang2 = peopleToLanguages.getOrDefault(friendship[1], new HashSet<>());\n if (Collections.disjoint(lang1, lang2)) {\n cantSpeak.add(new AbstractMap.SimpleEntry<>(friendship[0], friendship[1]));\n addPeopleToLang(friendship[0], lang1);\n addPeopleToLang(friendship[1], lang2);\n }\n }\n return cantSpeak;\n }\n\n private void addPeopleToLang(int friend, Set<Integer> languages) {\n for (int lang: languages) {\n langToPeople.computeIfAbsent(lang, e-> new HashSet<>()).add(friend);\n if (mostSpokenCount < langToPeople.get(lang).size()) {\n mostSpoken = lang;\n mostSpokenCount = langToPeople.get(lang).size();\n }\n }\n }\n\n private int learnLanguage(Map<Integer, Set<Integer>> peopleToLanguages, int friend, Set<Integer> lang) {\n if (!lang.contains(mostSpoken)) {\n peopleToLanguages.computeIfAbsent(friend, e-> new HashSet<>()).add(mostSpoken);\n return 1;\n }\n return 0;\n }\n}\n```
1
0
['Java']
0
minimum-number-of-people-to-teach
c++ | easy | step by step
c-easy-step-by-step-by-venomhighs7-2eic
\n# Code\n\nclass Solution {\npublic:\n\n\tvector<vector<int>> mem; \n bool check(vector<vector<int>>& a, int u, int v) {\n if(mem[u][v] != 0) return
venomhighs7
NORMAL
2022-10-01T04:42:19.778443+00:00
2022-10-01T04:42:19.778483+00:00
894
false
\n# Code\n```\nclass Solution {\npublic:\n\n\tvector<vector<int>> mem; \n bool check(vector<vector<int>>& a, int u, int v) {\n if(mem[u][v] != 0) return mem[u][v] == 1;\n for(int i=0; i<a[v].size(); i++) {\n if(find(a[u].begin(), a[u].end(), a[v][i]) != a[u].end()) {\n mem[v][u] = mem[u][v] = 1;\n return true;\n }\n }\n mem[u][v] = mem[v][u] = -1;\n return false;\n }\n\t\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m = languages.size(), ret = m, i;\n mem.assign(m + 1, vector<int>(m + 1, 0));\n\t\t\n for(i=0; i<m; i++)\n sort(languages[i].begin(), languages[i].end()); \n\t\t\t\n for(int lang=1; lang<=n; lang++) {\n int count = 0;\n vector<bool> teach(m, false);\n for(i=0; i<friendships.size(); i++) {\n int u = friendships[i][0] - 1;\n int v = friendships[i][1] - 1;\n if(check(languages, u, v)) \n continue;\n if(find(languages[u].begin(), languages[u].end(), lang) == languages[u].end()) {\n if(!teach[u])\n count++;\n teach[u] = true;\n }\n if(find(languages[v].begin(), languages[v].end(), lang) == languages[v].end()) {\n if(!teach[v])\n count++;\n teach[v] = true;\n }\n }\n ret = min(ret, count);\n }\n return ret;\n }\n};\n```
1
0
['C++']
2
minimum-number-of-people-to-teach
Python | Set
python-set-by-sr_vrd-p9cc
\nclass Solution:\n def cantCommunicate(self, user1: int, user2: int, languages: List[Set[int]]) -> bool:\n \'\'\'\n returns True iff user1 and
sr_vrd
NORMAL
2022-06-02T09:12:53.028893+00:00
2022-06-02T09:12:53.028917+00:00
362
false
```\nclass Solution:\n def cantCommunicate(self, user1: int, user2: int, languages: List[Set[int]]) -> bool:\n \'\'\'\n returns True iff user1 and user2 do not know any languages in common\n \'\'\'\n return len(languages[user1].intersection(languages[user2])) == 0\n \n def needToTeach(self, language: int, languages: List[Set[int]], missingConnections: Set[int]) -> int:\n \'\'\'\n returns number of users that have missing connections and do not know `language`\n \'\'\'\n return len([user for user in missingConnections if language not in languages[user]])\n \n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n\t\t# users are 1-indexed\n\t\t# we use sets instead of lists to improve linear lookup time to O(1)\n languages = [None] + [set(List) for List in languages]\n missingConnections = set()\n \n\t\t# identify all users that have at least one friend they can\'t communicate to\n for user1, user2 in friendships:\n if self.cantCommunicate(user1, user2, languages):\n missingConnections.add(user1)\n missingConnections.add(user2)\n \n\t\t# for each language count how many users with missing connections do not know that language\n\t\t# answer is the minimum of these counts\n minUsers = len(languages)\n for language in range(1, n + 1):\n minUsers = min(minUsers, self.needToTeach(language, languages, missingConnections))\n if minUsers == 0:\n return 0\n \n return minUsers\n```
1
0
['Ordered Set', 'Python']
1
minimum-number-of-people-to-teach
Brute force, 94% speed
brute-force-94-speed-by-evgenysh-62q1
Runtime: 1352 ms, faster than 93.94%\nMemory Usage: 27.2 MB, less than 59.60%\n\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[in
evgenysh
NORMAL
2021-07-13T18:48:19.635611+00:00
2021-07-13T18:48:19.635658+00:00
252
false
Runtime: 1352 ms, faster than 93.94%\nMemory Usage: 27.2 MB, less than 59.60%\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n languages = [set(lst) for lst in languages]\n incommunicado_friends = set()\n for friend_1, friend_2 in friendships:\n if not languages[friend_1 - 1] & languages[friend_2 - 1]:\n incommunicado_friends.add(friend_1 - 1)\n incommunicado_friends.add(friend_2 - 1)\n if not incommunicado_friends:\n return 0\n return min(sum(language not in languages[friend]\n for friend in incommunicado_friends)\n for language in range(1, n + 1))\n```
1
0
['Python', 'Python3']
0
minimum-number-of-people-to-teach
[Java] simple solution, beats 96.59%
java-simple-solution-beats-9659-by-octor-5v0p
\n\tpublic int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n\t\tint m = languages.length;\n\t\tboolean[][] speak = new boolean[m + 1][n +
octoray
NORMAL
2021-02-26T06:01:02.175416+00:00
2021-02-26T16:58:37.683263+00:00
295
false
```\n\tpublic int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n\t\tint m = languages.length;\n\t\tboolean[][] speak = new boolean[m + 1][n + 1];\n\t\tboolean[][] teach = new boolean[m + 1][n + 1];\n\t\tfor (int user = 0; user < m; user++) {\n\t\t\tint[] userLanguages = languages[user];\n\t\t\tfor (int language = 0; language < userLanguages.length; language++) {\n\t\t\t\tspeak[user + 1][userLanguages[language]] = true;\n\t\t\t}\n\t\t}\n\t\tList<int[]> listToTeach = new ArrayList<>();\n\t\tfor (int[] friend : friendships) {\n\t\t\tint userA = friend[0];\n\t\t\tint userB = friend[1];\n\t\t\tboolean hasCommonLanguage = false;\n\t\t\tfor (int language = 1; language <= n; language++) {\n\t\t\t\tif (speak[userA][language] && speak[userB][language]) {\n\t\t\t\t\thasCommonLanguage = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!hasCommonLanguage) {\n\t\t\t\tfor (int language = 1; language <= n; language++) {\n\t\t\t\t\tif (!speak[userA][language]) {\n\t\t\t\t\t\tteach[userA][language] = true;\n\t\t\t\t\t}\n\t\t\t\t\tif (!speak[userB][language]) {\n\t\t\t\t\t\tteach[userB][language] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlistToTeach.add(friend);\n\t\t\t}\n\t\t}\n\t\tint minLanguage = Integer.MAX_VALUE;\n\t\tint languageToTeach = 0;\n\t\tfor (int language = 1; language <= n; language++) {\n\t\t\tint count = 0;\n\t\t\tfor (int user = 1; user <= m; user++) {\n\t\t\t\tif (teach[user][language]) {\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (count < minLanguage) {\n\t\t\t\tminLanguage = count;\n\t\t\t\tlanguageToTeach = language;\n\t\t\t}\n\t\t}\n\t\tSet<Integer> setToTeach = new HashSet<>();\n\t\tfor (int[] friend : listToTeach) {\n\t\t\tint userA = friend[0];\n\t\t\tint userB = friend[1];\n\t\t\tif (!speak[userA][languageToTeach]) {\n\t\t\t\tsetToTeach.add(userA);\n\t\t\t}\n\t\t\tif (!speak[userB][languageToTeach]) {\n\t\t\t\tsetToTeach.add(userB);\n\t\t\t}\n\t\t}\n\t\treturn setToTeach.size();\n\t}\n```
1
1
[]
0
minimum-number-of-people-to-teach
[Python3] count properly
python3-count-properly-by-ye15-aoy3
Algo\nWe collect those who cannot communicate and find the most languages among them. Teach the language to those who haven\'t spoken it yet. \n\nImplementation
ye15
NORMAL
2021-02-10T22:56:19.595494+00:00
2021-02-10T22:56:19.595534+00:00
174
false
**Algo**\nWe collect those who cannot communicate and find the most languages among them. Teach the language to those who haven\'t spoken it yet. \n\n**Implementation**\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n m = len(languages)\n languages = [set(x) for x in languages]\n \n mp = {}\n for u, v in friendships: \n if not languages[u-1] & languages[v-1]: \n for i in range(n):\n if i+1 not in languages[u-1]: mp.setdefault(u-1, set()).add(i)\n if i+1 not in languages[v-1]: mp.setdefault(v-1, set()).add(i)\n \n ans = inf\n for i in range(n): \n val = 0\n for k in range(m): \n if i in mp.get(k, set()): val += 1\n ans = min(ans, val)\n return ans \n```\n\n**Analysis**\nTime complexity `O(MN)`\nSpace complexity `O(M+N)`\n\nEdited on 2/10/2021\nA clearner implementation is given below \n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n languages = [set(x) for x in languages]\n \n users = set()\n for u, v in friendships: \n if not languages[u-1] & languages[v-1]: \n users.add(u-1)\n users.add(v-1)\n \n freq = {}\n for i in users: \n for k in languages[i]:\n freq[k] = 1 + freq.get(k, 0)\n return len(users) - max(freq.values(), default=0)\n```
1
0
['Python3']
0
minimum-number-of-people-to-teach
C++ Self Explanatory Code
c-self-explanatory-code-by-prayag410-qck5
\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m = languages.size
prayag410
NORMAL
2021-02-09T07:04:13.069805+00:00
2021-02-09T07:04:13.069846+00:00
251
false
```\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m = languages.size();\n vector<set<int>> lang(m+1);\n for(int i=0; i<languages.size(); i++){\n for(int j=0;j<languages[i].size();j++){\n lang[i+1].insert(languages[i][j]);\n }\n }\n vector<vector<int>> uncommon;\n for(int j=0; j<friendships.size(); j++){\n int u =friendships[j][0], v = friendships[j][1];\n bool cmn = false;\n for(auto k:lang[u]){\n if(lang[v].find(k)!=lang[v].end()){\n cmn=true;\n break;\n }\n }\n if(cmn){\n continue;\n }\n uncommon.push_back(friendships[j]);\n }\n \n \n int ans = INT_MAX;\n for(int i=1; i<=n; i++){\n int cnt = 0;\n set<int> s;\n for(int j=0; j<uncommon.size(); j++){\n int u =uncommon[j][0], v = uncommon[j][1];\n if(lang[u].find(i)==lang[u].end()){\n s.insert(u);\n }\n if(lang[v].find(i)==lang[v].end()){\n s.insert(v);\n }\n \n }\n ans = min(ans, (int)s.size());\n }\n return ans;\n }\n};\n\n```
1
0
[]
0
minimum-number-of-people-to-teach
Simple C++ Solution
simple-c-solution-by-c0d1ngphenomena-blwu
\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n set<int> arr;\n
C0d1ngPhenomena
NORMAL
2021-01-24T15:36:20.380150+00:00
2021-01-24T15:36:58.455948+00:00
93
false
```\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n set<int> arr;\n \n //to store languages known by ith user\n unordered_map<int, map<int, int>> mp;\n \n for(int i = 0; i < languages.size(); i++) \n for(auto x : languages[i])\n mp[i+1][x]++;\n \n for(int i = 0; i < friendships.size(); i++) {\n int x = friendships[i][0], y = friendships[i][1];\n int flag = 0;\n \n for(int cnt = 1; cnt <= n; cnt++) {\n //do not insert into set if both can communicate with each other\n if(mp[x][cnt] and mp[y][cnt]) {\n flag = 1;\n break;\n }\n }\n \n if(flag == 0) \n arr.insert(x), arr.insert(y);\n }\n \n int cnta = INT_MAX;\n \n //here logic is that if the friendship set has any two mutually exclusive tuples than \n //they have to know the common language as the whole network has to communicate\n //so checking for each language check how many persons know it and take the minimum number needed to teach one\n \n //check how much persons we need to teach for each language\n for(int cnt = 1; cnt <= n; cnt++) {\n int maxi = 0;\n for(auto x : arr) \n if(!mp[x][cnt])\n maxi++;\n \n cnta = min(cnta, maxi);\n }\n \n return cnta;\n }\n};\n```
1
0
[]
0
minimum-number-of-people-to-teach
C++ bitmap with pruning 188 ms
c-bitmap-with-pruning-188-ms-by-crackiv-4wr5
Step 1: If two friends already speak the same language, we don\'t need to include them in the second step.\nStep 2: iterater all languages and check if the user
crackiv
NORMAL
2021-01-24T05:18:02.120322+00:00
2021-01-24T05:21:25.286208+00:00
136
false
Step 1: If two friends already speak the same language, we don\'t need to include them in the second step.\nStep 2: iterater all languages and check if the user speaks it. If not, set the bit and increase the user_count.\n\n```\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int users = languages.size();\n vector<vector<bool>> lmap(users + 1, vector<bool>(n+1));\n for(int i = 1; i <= users; ++i)\n for(auto l : languages[i-1])\n lmap[i][l] = true;\n int friends = 0;\n for(int i = 0, e = friendships.size(); i < e; ++i) {\n const auto& f = friendships[i];\n bool has_common_lang = false;\n for(int k = 1; k <= n && !has_common_lang; ++k)\n if (lmap[f[0]][k] && lmap[f[1]][k])\n has_common_lang = true;\n if (!has_common_lang) \n friendships[friends++] = f;\n }\n int ret = users;\n auto test_and_set = [&](int i, int l) { if (lmap[i][l]) return 0; lmap[i][l] = true; return 1;};\n for(int l = 1; l <= n; ++l) {\n int t = 0;\n for(int i = 0; i < friends; ++i) {\n t += test_and_set(friendships[i][0], l);\n t += test_and_set(friendships[i][1], l);\n }\n ret = min(t, ret);\n }\n return ret;\n }\n};\n```
1
0
[]
0
minimum-number-of-people-to-teach
Graph thought disappointed a lot!
graph-thought-disappointed-a-lot-by-sidd-2iq6
The code has good naming of variables to understand please check it out!!\nDisappointed with the problem a lot ! \n\n\nclass Solution {\npublic:\n int minimu
siddharthraja9849
NORMAL
2021-01-24T02:15:23.317207+00:00
2021-01-24T02:18:12.200095+00:00
148
false
The code has good naming of variables to understand please check it out!!\nDisappointed with the problem a lot ! \n```\n\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n set<int>peopleNotCommunicate;\n \n for(auto ele:friendships){\n int s=ele[0]-1;\n int d=ele[1]-1;\n map<int,int>lang;\n for(auto every:languages[s]){\n lang[every]=1;\n }\n \n bool flag=false;\n for(auto every:languages[d]){\n if(lang[every]==1){\n flag=true;\n break;\n }\n }\n \n if(!flag){\n peopleNotCommunicate.insert(s);\n peopleNotCommunicate.insert(d);\n }\n \n \n }\n \n map<int,int>mostPopularLanguage;\n \n for(auto ele:peopleNotCommunicate){\n for(auto every:languages[ele]){\n mostPopularLanguage[every]++;\n }\n }\n \n int mini=0;\n \n for(auto ele:mostPopularLanguage){\n mini=max(mini,ele.second);\n }\n \n \n return peopleNotCommunicate.size()-mini;\n \n \n }\n};\n\n```
1
1
['C', 'Ordered Set']
0
minimum-number-of-people-to-teach
javascript 176ms
javascript-176ms-by-henrychen222-yput
\nconst minimumTeachings = (n, languages, friendships) => {\n let ln = languages.length;\n let canCommunicate = initialize2DArrayNew(ln, n);\n for (let
henrychen222
NORMAL
2021-01-24T01:49:26.106289+00:00
2021-01-24T01:49:26.106316+00:00
144
false
```\nconst minimumTeachings = (n, languages, friendships) => {\n let ln = languages.length;\n let canCommunicate = initialize2DArrayNew(ln, n);\n for (let l = 0; l < ln; l++) {\n for (const x of languages[l]) {\n canCommunicate[l][x - 1] = true;\n }\n }\n let set = new Set();\n for (const fr of friendships) {\n let a = fr[0] - 1;\n let b = fr[1] - 1;\n let flag = false;\n for (const x of languages[a]) {\n if (canCommunicate[b][x - 1]) flag = true;\n }\n if (flag) continue;\n set.add(a);\n set.add(b);\n }\n let res = Number.MAX_SAFE_INTEGER;\n for (let i = 0; i < n; i++) {\n let teach = 0;\n for (const user of set) {\n if (!canCommunicate[user][i]) teach++;\n }\n res = Math.min(res, teach);\n }\n return res;\n};\n\nconst initialize2DArrayNew = (m, n) => {\n let data = [];\n for (let i = 0; i < m; i++) {\n let tmp = new Array(n).fill(false);\n data.push(tmp);\n }\n return data;\n};\n```
1
0
['JavaScript']
0
minimum-number-of-people-to-teach
python 7-lines
python-7-lines-by-darktiantian-wvuq
python\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n lang = [0] + list(map(set, languages))
darktiantian
NORMAL
2021-01-23T17:16:16.356703+00:00
2021-01-23T17:16:35.103648+00:00
138
false
```python\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n lang = [0] + list(map(set, languages))\n uncom = set() # someone may need learn new language\n for a, b in friendships:\n if not (lang[a] & lang[b]):\n uncom.add(a)\n uncom.add(b)\n return min(sum(i not in lang[p] for p in uncom) for i in range(1, n+1))\n```
1
0
['Python']
0
minimum-number-of-people-to-teach
Java Solution with comments
java-solution-with-comments-by-husilan-d76r
Iterate all the friendships to find the pair that don\'t have common lanagues\n2. If they don\'t have common lanagues, then check if this person is already in t
husilan
NORMAL
2021-01-23T16:48:39.395359+00:00
2021-01-23T16:48:39.395386+00:00
109
false
1. Iterate all the friendships to find the pair that don\'t have common lanagues\n2. If they don\'t have common lanagues, then check if this person is already in the set or not\n3. If it\'s not then add the lanagues of that person to the count array.\n4. Greedy choose the max languages (this is the languages for the friends that don\'t have common languages)\n```\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n int[] count=new int[n+1]; \n Set<Integer> set=new HashSet<Integer>();\n for(int i=0;i<friendships.length;i++){\n int u=friendships[i][0];\n int v=friendships[i][1];\n int[] l1=languages[u-1];\n int[] l2=languages[v-1];\n Arrays.sort(l1);\n Arrays.sort(l2);\n int ll1=0;\n int ll2=0;\n boolean flag=false;\n while(ll1<l1.length&&ll2<l2.length){\n if(l1[ll1]==l2[ll2]){\n flag=true;\n break;\n }else if(l1[ll1]<l2[ll2]){\n ll1++;\n }else{\n ll2++;\n }\n }\n if(!flag){\n if(!set.contains(u)){\n for(ll1=0;ll1<l1.length;ll1++){\n count[l1[ll1]]++;\n }\n set.add(u);\n }\n \n if(!set.contains(v)){\n for(ll2=0;ll2<l2.length;ll2++){\n count[l2[ll2]]++;\n }\n set.add(v);\n } \n }\n } \n int max=0;\n for(int i=1;i<=n;i++){\n max=Math.max(max, count[i]);\n }\n return set.size()-max;\n }\n}``\n```
1
0
[]
0