diff --git a/Hackerrank/Picking Numbers.py b/Hackerrank/Picking Numbers.py new file mode 100644 index 00000000..ef6f6b56 --- /dev/null +++ b/Hackerrank/Picking Numbers.py @@ -0,0 +1,73 @@ + from math import * + from builtins import staticmethod + from collections import Counter + from collections import defaultdict + from collections import namedtuple + from collections import deque + from queue import LifoQueue + import heapq + import functools + import hashlib + from datetime import datetime, timedelta + import json + import re + from itertools import * + import queue + + + def solve(n, a): + a.sort() + prev_count, cnt, res_min = 0, 1, a[0] + for i in range(1, n): + if a[i] == res_min + 1 or a[i] == res_min: + cnt += 1 + elif prev_count <= cnt: + prev_count = cnt + res_min = a[i] + cnt = 1 + if prev_count == 0: + return cnt + return prev_count + + + def main(): + n = int(input()) + a = list(map(int, input().split())) + print(solve(n, a)) + + + if __name__ == '__main__': + main() + + 0| + Add CommentPermalink + + yedinzon + 6 days ago + + C# Solution + + public static int pickingNumbers(List a) + { + int maxSubArray = 0, maxTemp = 0; + a.Sort(); + + do + { + findMaxArray(a); + if(maxSubArray < maxTemp) maxSubArray = maxTemp; + a.RemoveAt(0); + }while(a.Count() > maxSubArray); + + void findMaxArray(List list) + { + maxTemp = 0; + foreach(int num in list) + { + if(num - list[0] > 1) break; + maxTemp++; + } + } + + return maxSubArray; + } diff --git a/README.md b/README.md index 791a2e2c..d39468b7 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ In this repository, you can find the solutions (as source code) for the problems | [Nauman Chaudhary](https://github.com/nauman-chaudhary)
| Pakistan | Python | | | [Gourav Rusiya](https://github.com/GouravRusiya30)
| India | Java | https://www.hackerrank.com/gouravrusiya786 | | [Trushita Maurya](https://github.com/trushita23)
| India | Java +| [Revand S](https://github.com/revand5467)
| India | Python ### License [![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://github.com/ows-ali/Hacktoberfest/blob/master/LICENSE)