Python Interview Question asked in Tiger Analytics

preview_player
Показать описание
Check our Data Science & Analytics Courses on our website. We provide hands-on practical learning experience to our learners with 1-1 Live Doubt Clearance Support over Chat everyday and also you will learn Job Hunting Hacks. You will get projects and case studies that you can add in your resume and a lot more features are there inside this course.

➡️1. Data Science, Analytics & Job Hunting Super Combo Course (Paid Internship)
Рекомендации по теме
Комментарии
Автор

for i in range(1, max(List)+1):
if i not in List:
print(i)

lilythecutecat
Автор

Another approach with O(n):
l=[2, 3, 7, 1, 6, 8, -1, -10, 15]
a=[*range(1, len(l))]
for i in a:
if(i not in l):
print(i)
break

HEYTHERE-kowe
Автор

def leastpositive(a):
for i in range(1, len(a)+1):
if i not in a:
return(i)
break
else:
pass

a = [1, -1, 3, 7, 8, 100, 2, 5, -6]

print(leastpositive(a))

srirambalraj
Автор

Here is my solution...

l=[3, 7, 1, -1, 8, 10]
m=list(range(1, max(l)))
for i in m:
if i not in l:
print('the missing least integer is ', i)
break

sachindn
Автор

The following is my approach:
def least_positive(lst):
f = sorted([row for row in lst if row > 0])
g = [row for row in range(1, max(f)) if row not in f]
return sorted(g)[0]

umerkhalifa
Автор

lis=[2, 1, 4, 6, 3, 9, 13]
count=1
for i in lis:
if count not in lis:
print(count)
break
count+=1
this is simple and works fine

logeshlyrics
Автор

creating function(easy solution):

def min_pos(list_1):
for i in range(1, max(list_1)+1):
if (i not in list_1):
return(i)

krishnashinde
Автор

My solution:

input_list = [1, -1, 3, 7, 8, 0, 2, 5, -6]
min([x for x in range(min(input_list), max(input_list) + 1) if (x not in input_list) and (x>0)])


Having final interview tomorrow. Wish me the best fam!

manthanrathod
Автор

# Using dictionary:
# time Complexity: O(n)
# space comlexity: O(n)
li = [-1, 1, 2, 4, 5, 200, 235]
dic = {}
for i in range(1, len(li)+1):
dic[i] = 1
for i in li:
if i in dic:
dic[i]-=1
small = float('+inf')
for k, v in dic.items():
if v==1:
if k<=small:
small = k
print(small)

prakash
Автор

l1 = [1, -1, 3, 7, 8, 100, 2, 5, -6]
num = max(l1)
for i in range(1, num+1):
if i not in l1:
print (i)
break

SumitKumar-sjxw
Автор

This works fine too.

arr = [3, 7, -1, 8, 9, 10]

for i in range(1, max(arr)):
if i in arr:
continue
else:
print(i)
break

waqarmehdi
Автор

def
inp_list=sorted([i for i in inp_list if i>0])
i=0
while i<len(inp_list):
if i+1!=inp_list[i]:
return i+1
else:
i=i+1

assert find_missing_positive([1, -1, 3, 7, 8, 0, 2, 5, -6])==4
assert find_missing_positive([3, 7, -1, 8, 9, 10])==1

TechTalesalpha
Автор

another approach
first remove negative values using list comprehension
and using sorted of list comprehension of first output from range(min, max) and check with the values of list
x=[1, -1, 3, 7, 8, 0, 2, 5, -6]
l=sorted([i for i in x if i>0])
v=[j for j in range(l[0], l[-1]+1) if j not in l]
print(v[0])

vinayreddy
Автор

arr = [1, -1, 3, 7, 8, 100, 2, 5, -6]
i = 1
while i<len(arr):
if i not in arr:
print(i)
break
i+=1

nithin
Автор

my approach would be like this:

def least_positive_intiger ():
print('Please provide some input in numbers')
str1=input()
list1=str1.split(', ')
list1=[int(i) for i in list1]
return ([i for i in range(1, max(list1)) if i not in list1][0])

Here the first for loop is just for converting input string into a integer list. If someone directly wanna pass a list within the function like a parameter then the first for loop is not required. so ultimately it has only 1 for loop for solving the problem

wrickghosh
Автор

This is my approach:
list_a = [3, 7, -1, 8, 9, 10]
list_b = [ ]
min_of_a = min(list_a)
max_of_a = max(list_a)
for i in range(min_of_a, max_of_a):
if i not in list_a and i > 0:
list_b.append(i)
print(min(list_b))

janarthananstyles
Автор

a=[1, -1, 3, 7, 8, 0, 2, 5, -6]
b=[]
for i in range(0, 10):
for j in a:
if i == j:
break
else:
b.append(i)
print(min(b))

ank_kumar
Автор

nums=[-3, 40, 20, 6, -5, 1]
n=len(nums)
num=set(nums)
for i in range(1, n+2):
if i not in num:
return i

sm.prithiv
Автор

l=[3, 7, -1, 8, 9, 10]
l.sort()
a=[ ]
for i in range (1, max(l)):
if i not in l:
a.append(i)
print(a[0])

Tried this.

himeshbanerjee
Автор

l1=[1, 2, 4, 5, -1, -3, -7, 7, 8, 10]
l1.sort()
max_el=l1[len(l1)-1]
for i in range(1, max_el):
if i not in l1:
print(i)
break;

saipavankoppu