RUVIDEO
Поделитесь видео 🙏

HINDI CODING INTERVIEW QUESTION | Get product of all other elements | Python List Array Question |P

📁 Обучение 👁️ 17 📅 02.12.2023

LEARN PROGRAMMING IN HINDI
In this video tutorial, we will write a solution for frequently asked coding interview questions in software engineering job interviews. If you are given an array or list in python, get product of all other elements. We solved this question in the earlier video using total product and division.

The easy method is shown in PART 1 video here: https://youtu.be/Y8gxfQXnoF4

In this tutorial, we will solve it using a different method, and without using division or total product. We will calculate two arrays or lists, one for prefix and one for the suffix. Then for each given index, we will multiply the value at that index from prefix and suffix array. See the code below.

This problem is asked during coding and software job interviews at big tech companies like Google, Facebook, Apple, Amazon, Microsoft, Tata, TCS, Infosys, L&T, and other big software companies. Pass your coding interview by practicing on leetcode and daily coding problems as well as employing this solution and other coding problem-solving tips.

SOLUTION PYTHON CODE:
Buy the book "The C Programming Language" from Amazon: https://amzn.to/3erULEd

# CODING PROBLEM: EASY TO MEDIUM COMPLEXITY.
# Given an array of integers, return a new array such that each element at index i of the new array
# is the product of all elements original array except the one at i.
# Input = [1, 2, 3, 4, 5]
# Output = [120, 60, 40, 30, 24]

# Solution 2: Calculate prefix values, calculate suffix values, arrive at the output array by multiplying those.

def convertArray(a):
prefix_array = []
for i in a:
if prefix_array: # prefix is not empty
prefix_array.append(prefix_array[-1] * i)
else: # empty
prefix_array.append(i)

suffix_array = []
for i in reversed(a):
if suffix_array: # prefix is not empty
suffix_array.append(suffix_array[-1] * i)
else: # empty
suffix_array.append(i)
suffix_array = list(reversed(suffix_array))

result = []
for i in range(len(a)):
if i == 0: # first index
result.append(suffix_array[i+1])
elif i == (len(a)-1): # last index
result.append(prefix_array[i-1])
else:
result.append(prefix_array[i-1] * suffix_array[i+1])

return result


test = [1,2,3,4,5]
print(convertArray(test))

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «HINDI CODING INTERVIEW QUESTION | Get product of all other elements | Python List Array Question |P», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.