Question

using Python --- from typing import List THREE_BY_THREE = [[1, 2, 1], [4, 6, 5], [7,...

using Python ---

from typing import List


THREE_BY_THREE = [[1, 2, 1],
[4, 6, 5],
[7, 8, 9]]

FOUR_BY_FOUR = [[1, 2, 6, 5],
[4, 5, 3, 2],
[7, 9, 8, 1],
[1, 2, 1, 4]]

UNIQUE_3X3 = [[1, 2, 3],
[9, 8, 7],
[4, 5, 6]]

UNIQUE_4X4 = [[10, 2, 3, 30],
[9, 8, 7, 11],
[4, 5, 6, 12],
[13, 14, 15, 16]]

def find_peak(elevation_map: List[List[int]]) -> List[int]:
"""Return the cell that is the highest point in the elevation map
elevation_map.

Precondition: elevation_map is a valid elevation map.
Every elevation value in elevation_map is unique.

>>> find_peak(UNIQUE_3X3)
[1, 0]
>>> find_peak(UNIQUE_4X4)
[0, 3]
"""

pass # remove this line when you implement this function

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE IN PYTHON:

def find_peak(elevation): #method to find and return cell with max elevation
#setting first cell to max
maxRow=0
maxCol=0
#iterating through all the cells
for row in range(len(elevation)):
for col in range(len(elevation[row])):
#checking if current cell elevation is more than temporary max
if elevation[row][col]>elevation[maxRow][maxCol]:
maxRow=row
maxCol=col
return [maxRow,maxCol] #return result

#testing method
UNIQUE_3X3=[[1,2,3],[9,8,7],[4,5,6]]
UNIQUE_4X4=[[10,2,3,30],[9,8,7,11],[4,5,6,12],[13,14,15,16]]
print(find_peak(UNIQUE_3X3))
print(find_peak(UNIQUE_4X4))

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
using Python --- from typing import List THREE_BY_THREE = [[1, 2, 1], [4, 6, 5], [7,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • List of Indexes Complete the following function. Note that neither item List nor index list should...

    List of Indexes Complete the following function. Note that neither item List nor index list should be mutated 1 from typing import List 3 def find value indexes (iten list: list. index List: Listint). V: object) + List[int]: may appear multiple times in iton list. index list contains zero or more indexes. Return a list of the indexes from index list at which v appears in ite list. Precondition: the values in index_list are valid indexes in its list. >>>...

  • can you finish implementing the functions below ********************************************************************************************************** import urllib.request from typing import List, TextIO #...

    can you finish implementing the functions below ********************************************************************************************************** import urllib.request from typing import List, TextIO # Precondition for all functions in this module: Each line of the url # file contains the average monthly temperatures for a year (separated # by spaces) starting with January. The file must also have 3 header # lines. DATA_URL = 'http://robjhyndman.com/tsdldata/data/cryer2.dat' def open_temperature_file(url: str) -> TextIO: '''Open the specified url, read past the three-line header, and return the open file. ''' ... def avg_temp_march(f:...

  • Please use python. You can import only: from typing import Dict, List from PIL import Image...

    Please use python. You can import only: from typing import Dict, List from PIL import Image import random Questions are: --------------------------------------------------------------------------------------------------------------------------------- 1. def rotate_picture_90_left(img: Image) -> Image: """Return a NEW picture that is the given Image img rotated 90 degrees to the left. Hints: - create a new blank image that has reverse width and height - reverse the coordinates of each pixel in the original picture, img, and put it into the new picture """ -----------------------------------------------------------------------------------------------------------------------------------    2. def...

  • from __future__ import annotations from typing import Any, Optional class _Node: """A node in a linked...

    from __future__ import annotations from typing import Any, Optional class _Node: """A node in a linked list. Note that this is considered a "private class", one which is only meant to be used in this module by the LinkedList class, but not by client code. === Attributes === item: The data stored in this node. next: The next node in the list, or None if there are no more nodes. """ item: Any next: Optional[_Node] def __init__(self, item: Any) ->...

  • Python 1 import matplotlib.pyplot as plt 2 import numpy as np 3 4 abscissa = np.arange(20) 5 plt....

    python 1 import matplotlib.pyplot as plt 2 import numpy as np 3 4 abscissa = np.arange(20) 5 plt.gca().set_prop_cycle( ’ color ’ , [ ’ red ’ , ’ green ’ , ’ blue ’ , ’ black ’ ]) 6 7 class MyLine: 8 9 def __init__(self, * args, ** options): 10 #TO DO: IMPLEMENT FUNCTION 11 pass 12 13 def draw(self): 14 plt.plot(abscissa,self.line(abscissa)) 15 16 def get_line(self): 17 return "y = {0:.2f}x + {1:.2f}".format(self.slope, self.intercept) 18 19 def __str__(self):...

  • How to remove all occurrences of 2 from list2. Then display the list. Python import random...

    How to remove all occurrences of 2 from list2. Then display the list. Python import random list1 = [] for i in range (10): list1.append(random.randint(1,4)) print('List 1:') print(list1) list2 = [] list2.append(list1[5:]) print('List 2:') print(list2) list2.remove ******** (This is the part I am having trouble on!!) print('List 2 with all 2s removed:') print(list2) Sample output: List 1: [4, 1, 1, 3, 3, 3, 2, 4, 2, 4] List2: [3, 2, 4, 2, 4] List 2 with all 2s removed: [3,...

  • [Python] Construct Tree Using Inorder and Preorder Given Preorder and Inorder traversal of a binary tree,...

    [Python] Construct Tree Using Inorder and Preorder Given Preorder and Inorder traversal of a binary tree, create the binary tree associated with the traversals.You just need to construct the tree and return the root. Note: Assume binary tree contains only unique elements. Input format : Line 1 : n (Total number of nodes in binary tree) Line 2 : Pre order traversal Line 3 : Inorder Traversal Output Format : Elements are printed level wise, each level in new line...

  • def _merge(lst: list, start: int, mid: int, end: int) -> None: """Sort the items in lst[start:end]...

    def _merge(lst: list, start: int, mid: int, end: int) -> None: """Sort the items in lst[start:end] in non-decreasing order. Precondition: lst[start:mid] and lst[mid:end] are sorted. """ result = [] left = start right = mid while left < mid and right < end: if lst[left] < lst[right]: result.append(lst[left]) left += 1 else: result.append(lst[right]) right += 1 # This replaces lst[start:end] with the correct sorted version. lst[start:end] = result + lst[left:mid] + lst[right:end] def find_runs(lst: list) -> List[Tuple[int, int]]: """Return a...

  • You may import the following library functions in your module: from fractions import gcd from math...

    You may import the following library functions in your module: from fractions import gcd from math import floor from random import randint You may also use: • the built-in pow() function to compute modular exponents efficiently (i.e., ak mod n can be written in Python as pow(a,k,n)), • the sum() function returns the sum of a list of integers (sum(1,2,3,4) returns 10). problem 1 a. Implement a function invPrime(a, p) that takes two integers a and p > 1 where...

  • def most_expensive_item(price_list: List[list]) -> str: """Return the name of the most expensive item in price_list. Precondition:...

    def most_expensive_item(price_list: List[list]) -> str: """Return the name of the most expensive item in price_list. Precondition: price_list is a list of lists in the following format: [ [str, int], [str, int], ... ] where each 2-element list represents a name (str) and a price (int) of an item. price_list has at least one element. >>> price_list = [["apple", 1], ["sugar", 5], ["mango", 3], ... ["coffee", 9], ["trail mix", 6]] >>> most_expensive_item(price_list) """ please complete the function body in Python

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT