Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved the Hackerrank challenge 'Picking Numbers' #1256

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Hackerrank/Picking Numbers.py
Original file line number Diff line number Diff line change
@@ -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<int> 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<int> list)
{
maxTemp = 0;
foreach(int num in list)
{
if(num - list[0] > 1) break;
maxTemp++;
}
}

return maxSubArray;
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) <br> <img src="https://github.com/nauman-chaudhary.png" width="100" height="100"> | Pakistan | Python | |
| [Gourav Rusiya](https://github.com/GouravRusiya30) <br> <img src="https://github.com/GouravRusiya30.png" width="100" height="100"> | India | Java | https://www.hackerrank.com/gouravrusiya786 |
| [Trushita Maurya](https://github.com/trushita23) <br> <img src="https://github.com/trushita23.png" width="100" height="100"> | India | Java
| [Revand S](https://github.com/revand5467) <br> <img src="https://github.com/revand5467.png" width="100" height="100"> | India | Python
### License

[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://github.com/ows-ali/Hacktoberfest/blob/master/LICENSE)