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

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

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