Find the number with the most digits.

If two numbers in the argument array have the same number of digits, return the first one in the array.

Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code:
def find_longest(arr):
	

Solutions:
def find_longest(xs):
	return max(xs, key=lambda x: len(str(x)))


def find_longest(arr):
	return max(arr, key=lambda x: len(str(x)))


def find_longest(arr):
	max_lenght = 0
	max_index = 0
	for cur_num in arr:
		lenght = len(str(cur_num))
		if lenght > max_lenght:
			max_lenght = lenght
			max_index = arr.index(cur_num)
	return arr[max_index]


def find_longest(arr):
	arr.sort(reverse=True)
	return arr[0]


def find_longest(arr):
	e = [len(str(i)) for i in arr]
	return arr[e.index(max(e))]


def find_longest(arr):
	_len_arr = []
	for i in arr:
		_len_arr.append(len(str(i)))
	return arr[_len_arr.index(max(_len_arr))]


def find_longest(arr):
	return next((s for s in arr if len(str(s)) == len(str(max(arr)))))


def find_longest(arr):
	return [i for i in arr if len(str(i)) == len(str(max(arr)))][0]


from math import log10

def find_longest(arr):
	return max(arr, key=lambda n: int(log10(n)))


def find_longest(arr):
	newArray = list(map(str, arr))
	return int(max(newArray, key=len))


from math import log10
from operator import itemgetter

def find_longest(arr):
	return max(list(zip((int(log10(a)) for a in arr), arr)), key=itemgetter(0))[1]


def find_longest(arr):
	max_digits = arr[0]
	for i in range(1, len(arr)):
		if len(str(arr[i])) > len(str(max_digits)):
			max_digits = arr[i]
	return max_digits


def find_longest(arr):
	longest = 0
	result = 0
	for item in arr:
		if len(str(item)) > longest:
			longest = len(str(item))
			result = item
	return result


def find_longest(arr):
	max = -1
	result = 0
	for num in arr:
		l = len(list(str(num)))
		if l > max:
			max = l
			result = num
	return result


def find_longest(arr):
	return max(arr, key=lambda n: len(str(n)))


def find_longest(arr):
	largest = 0
	for i in range(len(arr)):
		a = arr[i] / 10
		x = 1
		while a > 1:
			a = a / 10
			x += 1
		if x > largest:
			largest = x
			largestVal = arr[i]
	return largestVal


from functools import reduce

def find_longest(arr):
	return reduce(lambda max, cur: cur if len(str(cur)) > len(str(max)) else max, arr)


def find_longest(arr):
	return max(arr, key=lambda x: int(__import__('math').log10(abs(x))))


def find_longest(arr):
	l = list(map(str, arr))
	return int(sorted(l, key=lambda x: (len(str(x)), -l.index(x)))[-1])


def find_longest(arr):
	result = str(arr[0])
	for i in range(len(arr)):
		if len(str(arr[i])) > len(result):
			result = str(arr[i])
	return int(result)


def find_longest(arr):
	return int(max([str(n) for n in arr], key=len))


find_longest = lambda arr: int(max([str(i) for i in arr], key=len))


def find_longest(arr):
	return int(max(map(str, arr), key=len))


def find_longest(arr):
	return int(max([str(number) for number in arr], key=len))


def find_longest(arr):
	weishu = [1]
	for number in arr:
		count = 0
		while number != 0:
			number = number // 10
			count = count + 1
		weishu.append(count)
	a = max(weishu)
	for number1 in arr:
		number = number1
		count = 0
		while number != 0:
			number = number // 10
			count = count + 1
		print(count)
		if count == a:
			return number1


def find_longest(arr):
	max_len = 0
	for i in arr:
		if len(str(i)) > max_len:
			max_len = len(str(i))
			max_num = i
	return max_num


def find_longest(arr):
	return sorted(list(map(lambda x: (len(str(x)), x), arr)), key=lambda x: -x[0])[0][1]


def find_longest(arr):
	return list(filter(lambda x: len(str(x)) == len(str(max(arr))), arr))[0]


from math import floor, log10

def find_longest(arr):
	digits = lambda a: floor(log10(a))
	return max(arr, key=digits)


def find_longest(arr):
	biggest = arr[0]
	for num in arr:
		if len(str(num)) > len(str(biggest)):
			biggest = num
	return biggest


def find_longest(arr):
	b = 0
	result = 0
	for i in arr:
		if len(str(i)) > b:
			b = len(str(i))
			result = i
	return result


def find_longest(arr):
	r = [len(str(x)) for x in arr]
	return arr[r.index(max(r))]


def find_longest(arr):
	box = []
	base = 0
	for (i, x) in enumerate(arr):
		for j in str(x):
			box.append(j)
			if len(box) > base:
				base = len(box)
				result = i
		box.clear()
	return arr[result]


def find_longest(arr):
	list1 = []
	for i in arr:
		x = str(i)
		z = len(x)
		list1.append(z)
		y = list1.index(max(list1))
	return arr[y]


def find_longest(arr):
	realnum = 0
	for item in arr:
		if len(str(item)) > len(str(realnum)):
			realnum = item
	return realnum


def find_longest(arr):
	mn = ln = -1
	for n in arr:
		l = len(str(n))
		if l > ln:
			(mn, ln) = (n, l)
	return mn


def find_longest(arr):
	arr.sort(reverse=True)
	return max(arr)


def find_longest(arr):
	a = sorted(arr, key=lambda x: len(str(x)))
	for i in a:
		if len(str(i)) == len(str(a[-1])):
			return i


def find_longest(arr):
	length = []
	for (i, v) in enumerate(arr):
		length.append([len(str(v)), i])
	multiple = []
	for z in length:
		if z[0] == sorted(length)[-1][0]:
			multiple.append(z)
	return arr[multiple[0][1]]


def find_longest(arr):
	res = ''
	for i in arr:
		if len(str(res)) < len(str(i)):
			res = i
	return res


def find_longest(arr):
	counter = 0
	number = 0
	for n in arr:
		str_n = str(n)
		if len(str_n) > counter:
			counter = len(str_n)
			number = n
	return number


def find_longest(arr):
	lst = []
	empty = []
	for i in arr:
		i = str(i)
		lst.append(len(i))
	for j in lst:
		empty.append(j)
	empty.sort()
	maxvaldig = empty[-1]
	if empty.count(maxvaldig) > 1:
		index = lst.index(maxvaldig)
		realmaxval = arr[index]
	else:
		index = lst.index(maxvaldig)
		realmaxval = arr[index]
	return realmaxval


def find_longest(arr):
	d = {}
	for i in range(0, len(arr)):
		z = [int(x) for x in str(arr[i])]
		l = len(z)
		s = [str(j) for j in z]
		p = int(''.join(s))
		d.update({p: l})
	m = max(d, key=d.get)
	return m


def find_longest(arr):
	highest_len = 0
	highest_len_name = 0
	for i in arr:
		if len(str(i)) > highest_len:
			highest_len = len(str(i))
			highest_len_name = i
	return highest_len_name


def find_longest(arr):
	print(len(str(arr[0])))
	res = []
	for i in arr:
		res.append(len(str(i)))
	return arr[res.index(sorted(res, reverse=True)[0])]


def find_longest(arr):
	mx = 0
	for n in arr:
		if len(str(n)) > len(str(mx)):
			mx = n
	return mx


def find_longest(arr):
	arr_str = map(str, arr)
	res = max(arr_str, key=len)
	return int(res)


def find_longest(l):
	(m, c) = (max(list(map(lambda x: len(str(x)), l))), 0)
	for i in list(map(lambda x: len(str(x)), l)):
		if i == m:
			return l[c]
		c += 1


def find_longest(arr):
	lst = []
	for item in arr:
		lst.append(str(item))
	return int(max(lst, key=len))


def find_longest(arr):
	convert = []
	for num in arr:
		convert.append(str(num))
	return int(sorted(convert, key=len, reverse=True)[0])


def find_longest(arr):
	longest = 0
	number = 0
	for i in arr:
		if len(str(i)) > longest:
			longest = len(str(i))
			number = i
	return number


def find_longest(arr):
	return [x for x in arr if len(str(x)) == len(str(sorted(arr)[-1]))][0]


def find_longest(arr):
	a = max(arr)
	for i in range(len(arr)):
		if len(str(arr[i])) == len(str(a)):
			return arr[i]


find_longest = lambda a: max(a, key=lambda n: len(str(n)))


def find_longest(arr):
	length = 0
	noomber = 0
	for x in arr:
		if length < len(str(x)):
			noomber = x
			length = len(str(x))
	return noomber


def find_longest(arr):
	for i in sorted(arr, key=lambda x: len(str(x))):
		if len(str(i)) == max((len(str(i)) for i in arr)):
			return i


def find_longest(arr):
	arr = [str(i) for i in arr]
	L = len(max(arr, key=len))
	return int([i for i in arr if len(i) == L][0])


def find_longest(arr):
	l = 0
	a = 0
	ind = 0
	for i in range(len(arr)):
		a = str(arr[i])
		if l < len(a):
			l = len(a)
			ind = i
	return arr[ind]


def find_longest(arr):
	s_arr = []
	for i in arr:
		s_arr.append(str(i))
	number = max(s_arr, key=len)
	return int(number)


def find_longest(arr):
	max_length = 0
	max_index = 0
	for cur_num in arr:
		length = len(str(cur_num))
		if length > max_length:
			max_length = length
			max_index = arr.index(cur_num)
	return arr[max_index]


def find_longest(arr, high=''):
	for x in arr:
		s = str(x)
		if len(s) > len(high):
			high = s
	return int(high)


def find_longest(arr):
	arr = list(map(str, arr))
	sorted_arr = sorted(arr, key=len, reverse=True)
	return int(sorted_arr[0])


def find_longest(arr):
	m = len(str(max(arr)))
	for x in arr:
		if len(str(x)) == m:
			return x


def find_longest(arr):
	max = len(str(arr[0]))
	max_a = arr[0]
	for a in arr:
		print(a)
		if len(str(a)) > max:
			max = len(str(a))
			max_a = a
	return max_a


def find_longest(arr):
	string_array = [str(num) for num in arr]
	max_length = -1
	for ele in string_array:
		if len(ele) > max_length:
			max_length = len(ele)
			result = ele
	return int(result)


def find_longest(arr):
	return arr[[len(str(element)) for element in arr].index(max([len(str(element)) for element in arr]))]


def find_longest(arr):
	l = [len(str(a)) for a in arr]
	return arr[l.index(max(l))]


def find_longest(arr):
	ln = 0
	index = 0
	for i in arr:
		listln = len(str(i))
		if listln > ln:
			ln = listln
			index = arr.index(i)
	return arr[index]


def find_longest(a):
	return sorted([x for x in a], key=lambda x: -len(str(x)))[0]


def find_longest(arr):
	helper_len = arr[0]
	for i in arr:
		if len(str(i)) > len(str(helper_len)):
			helper_len = i
	return int(helper_len)


import math

def find_longest(arr):
	x = arr[0]
	for each in arr:
		if len(str(each)) > len(str(x)):
			x = each
	return x


def find_longest(arr):
	listofstrings = [str(item) for item in arr]
	longest = max(listofstrings, key=len)
	longestToInt = int(longest)
	return longestToInt


def find_longest(arr):
	m = 0
	ml = 0
	for i in arr:
		l = len(str(i))
		if l > ml:
			ml = l
			m = i
	return m


def find_longest(arr):
	max_len = 0
	for el in arr:
		if len(str(el)) > max_len:
			max_len = len(str(el))
	for el in arr:
		if len(str(el)) == max_len:
			return el


def find_longest(arr):
	longest_item = 0
	i = 0
	while i < len(arr):
		if len(str(longest_item)) < len(str(arr[i])):
			longest_item = arr[i]
			i += 1
		else:
			i += 1
	return longest_item


def find_longest(arr):
	for x in arr:
		if x == max(arr, key=lambda n: len(str(n))):
			return x


def find_longest(arr):
	str_lst = list(map(str, arr))
	l = []
	for i in str_lst:
		l.append(len(i))
	return arr[l.index(max(l))]


def find_longest(arr):
	x = ''
	for i in arr:
		if len(str(i)) > len(x):
			x = str(i)
	return int(x)


def find_longest(arr):
	arr = [str(i) for i in arr]
	m_len = lambda x: len(x)
	return int(max(arr, key=m_len))


def find_longest(arr):
	max = 0
	t = 0
	for i in arr:
		if len(str(i)) > max:
			max = len(str(i))
			t = i
		else:
			continue
	return t


def find_longest(arr):
	longest_len = 0
	longest = None
	for el in arr:
		sample_len = len(str(el))
		if sample_len > longest_len:
			longest_len = sample_len
			longest = el
	return longest


def find_longest(arr):
	ml = len(str(max(arr)))
	return next((x for x in arr if len(str(x)) == ml))


def find_longest(arr):
	digit_lengths = list(map(lambda x: len(str(x)), arr))
	return arr[digit_lengths.index(max(digit_lengths))]


def find_longest(arr):
	most_digits = arr[0]
	for i in arr:
		if len(str(i)) > len(str(most_digits)):
			most_digits = i
	return most_digits


def find_longest(arr):
	ret = arr[0]
	for x in arr:
		if len(str(x)) > len(str(ret)):
			ret = x
	return ret


def find_longest(arr):
	copy = list(arr)
	i = 0
	while i < len(copy):
		copy[i] = len(str(copy[i]))
		i = i + 1
	maximum = max(copy)
	index = copy.index(maximum)
	return arr[index]


def find_longest(arr):
	i = 0
	max_len = arr[0]
	while i != len(arr):
		if len(str(arr[i])) > len(str(max_len)):
			max_len = arr[i]
		i += 1
	return max_len


def find_longest(arr):
	f = 0
	res = 0
	for i in arr:
		if i // 10 ** f != 0 and i > res:
			res = i
			while i // 10 ** f != 0:
				f += 1
	return res