+ 1
2D-array
Hey guys! I am a beginner programer and I have a problem. so i have a 2d array, let’s say it has 4 columns (Product, item code, quantity and price) I wish to find the product with the highest price, so I look specifically at the price column. it should look something like this: for column (3) for rows in range (100): ….. However, this way does not work. Can anyone pls help?
2 Respostas
+ 5
Екатерина Радаева ,
in python it could be like this:
....
max_ = ... # get first element from column 4
for line in arr:
if (buf := line[3]) > max_:
max_ = ...# assign current item to max_
....
+ 1
Idk about python syntax but this should be something like that (just the concept)
MaxPrice = 0;
For row in array:
Price = row[3];
If price > maxprice:
Maxprice = price;
This have a time complexity of O(n) and space O(1)