Convert the python codes into scala code

Assignment Help Python Programming
Reference no: EM133465203

Each of the below listed codes should converted to Scala Code .

Python code 1
def HistogramArea(arr):
stack = list()
max_area = 0
index = 0
while index < len(arr):
if (not stack) or (arr[stack[-1]] <= arr[index]):
stack.append(index)
index +=1
else:
top_of_stack = stack.pop()
area = (arr[top_of_stack] *
((index - stack[-1] -1 )
if stack else index))
max_area = max(max_area,area)
while stack:
top_of_stack = stack.pop()
area = (arr[top_of_stack] *
((index - stack[-1] -1 )
if stack else index))
max_area = max(max_area,area)
return max_area
input = [int(x) for x in input()]
print(HistogramArea(input))

#sample for testing [6, 3, 1, 4, 12, 4]

Python code 2
global maximum

def LongestIncreasingSequence(arr, n):
global maximum
if n == 1:
return 1

meh = 1
for i in range(1, n):
res = LongestIncreasingSequence(arr, i)
if arr[i - 1] < arr[n -1] and res + 1 > meh:
meh = res + 1
maximum = max(maximum, meh)
return meh
def lis(arr):
global maximum
n = len(arr)
maximum = 1
LongestIncreasingSequence(arr, n)
return maximum

input = [int(x) for x in input()]
n = len(input)
# keep this function call here
print(lis(input))
#sample for testing [9, 9, 4, 2]

Python code 3
no_of_chars = 256


def MinWindowSubstring(string, pat):

len1 = len(string)
len2 = len(pat)


if len1 < len2:

print("No such window exists")
return ""

hash_pat = [0] * no_of_chars
hash_str = [0] * no_of_chars

# Store occurrence ofs characters of pattern
for i in range(0, len2):
hash_pat[ord(pat[i])] += 1

start, start_index, min_len = 0, -1, float('inf')

# Start traversing the string
count = 0 # count of characters
for j in range(0, len1):

# count occurrence of characters of string
hash_str[ord(string[j])] += 1

# If string's char matches with
# pattern's char then increment count
if (hash_str[ord(string[j])] <=
hash_pat[ord(string[j])]):
count += 1

# if all the characters are matched
if count == len2:

# Try to minimize the window
while (hash_str[ord(string[start])] >
hash_pat[ord(string[start])] or
hash_pat[ord(string[start])] == 0):

if (hash_str[ord(string[start])] >
hash_pat[ord(string[start])]):
hash_str[ord(string[start])] -= 1
start += 1

# update window size
len_window = j - start + 1
if min_len > len_window:

min_len = len_window
start_index = start

# If no window found
if start_index == -1:
print("No such window exists")
return ""

# Return substring starting from
# start_index and length min_len
return string[start_index: start_index + min_len]

 

#sample for test data.
#string = "ahffaksfajeeubsne"
#pat = "jefaa"


Type = input()
x = Type[0]
y = Type[1]

print(MinWindowSubstring(x,y))

Reference no: EM133465203

Questions Cloud

Consider how you will use the e-portfolio after completion : Consider how you will use the e-portfolio after the completion of the course? How will you use the final product to enhance your personal branding?
Relationship between trusting world and shaping the world : What is the relationship between trusting the world and shaping the world? Why do you think there is adistinct difference in this relationship?
What is equity and how can you apply the concept of equity : What is equity and how can you apply the concept of equity is not about equality in your life with specific examples? What is diversity and what are the benefit
Discuss memories of their own childhood : Sanders and White both discuss memories of their own childhood and reflect on these within the scope of becoming fathers.
Convert the python codes into scala code : Convert the python codes into Scala code - Each of the below listed codes should converted to Scala Code
Develop the companys distribution strategy : Explain how you will use the feedback you received on your marketing plan. Develop the company's distribution strategy, including rationale for approach chosen.
What is campbells thesis : Was there any aspect of this week's reading that you did not understand? What is Campbell's thesis? What is he trying to prove in Hero with a Thousand Faces?
What are some specific challenges to low-income families : What are some specific challenges to low-income families or those living in poverty face? How can these challenges and associated stereotypes of low-income
Some distinctions between privacy and privacy laws : What are some distinctions between privacy and privacy laws? How should they be upheld by the criminal justice system?

Reviews

len3465203

7/10/2023 2:46:41 AM

Please convert the attached 3 python codes into Scala code each one code is separated from each others and they can be run alone. We have 3 different codes written in python with sample data to test them.

Write a Review

Python Programming Questions & Answers

  How to calculate square or rectangle edges and center

How to calculate square or rectangle edges and center. You just need one formula for edges and one formula for centers.

  Create topics along with the probability distribution

Create topics along with the probability distribution for each word in our vocabulary for each topic and Import the positive.csv dataset you have created

  Construct a python function named finder that takes two

Construct a Python function named finder that takes two string parameters, needle and haystack. Your function should find the first.

  Extract the data and transform the data

Extract the data and transform the data into the XML format - deviation from the XML structure - The "id"s must be unique, so if there are multiple instances

  Calculate x and y using the same initial conditions

Calculate x and y using the same initial conditions and parameters you did for the previous question, but this time run it for 500 iterations.

  Write a function that returns the length and starting index

Longest sorted subsequence. Write a function longest_monot one ( ) that returns the length and starting index of the longest contiguous sorted.

  Write a program in python to draw a blue triangle

Write a program in Python to draw a blue triangle in a drawing window. Write a program in Python that moves the triangle in an animated movement. Write a program in Python to draw a simplified face.

  Write a python script called passmerger that merge contents

CSCI 3351: Write a Python script called passmerger that will merge the contents of two simplified user account tables in a database as described below. The script uses one command line argument that represents the name of the database file.

  CS 6140 Data Mining Assignment

CS 6140 Data Mining Assignment Help and Solution, The University of Utah - Assessment Writing Service - Describe how you implemented this experiment

  What is the expected password for lab

What is the expected password for lab6-1? Explain how you were able to determine this.

  Write program that uses a function that returns a count

Write program that uses a function that returns a count of all letter es whether it's upper or lower case in a sentence.

  Write python program that computes factorial of an integer

Problem 2: Write a Python program that computes the factorial of an integer X (the program should ask the user to enter the value of X).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd