1- def getLongestSeq(a, n): maxIdx = 0 maxLen = 0 currlen = e currIdx = 0 for k in range(n): if a[k] < ®: currlen +=1 3. 4 5 6 8 9. # New sequence, store # beginning index. if currlen == 1: currIdx = k 1 2 3 else: if currLen > maxLen: maxLen = currLen maxIdx = currIdx currLen = 0 4 5 9. if maxlen > 0: print(a[maxIdx:maxIdx maxLen]) else: 2 3\ print("No negative sequence detected.") 4 5 arr=list(map(int,input().split(" "))) 6 n len(arr) 7 getlongestSeq(arr, n)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Find the algorithm time complexity and write type recurrence relation.

Run
O Debug
I Stop
E Share A sSave
{} Beautify
OnlineGDB beta
main.py
online compiler and debugger for c/c++
1- def getLongestSeq(a, n):
maxIdx = 0
maxLen = 0
currLen = 0
currIdx = 0
for k in range (n):
if a[k] < 0:
code. compile. run. debug. share.
3
4
IDE
My Projects
7-
Classroom new
8
currLen +=1
Learn Programming
10
# New sequence, store
# beginning index.
if currlen == 1:
currIdx = k
Programming Questions
11
Sign Up
12-
13
Login
14 -
else:
if currLen > maxLen:
maxLen = currLen
maxIdx = currIdx
currLen = 0
15-
fy
+ 24.8K
16
17
18
19
20-
if maxlen > 0:
21
print(a[maxIdx:maxIdx maxLen])
22-
else:
23
print("No negative sequence detected.")
24
25 arr=list(map(int, input().split(" ")))
26 n = len(arr)
27 getLongestSeq(arr, n)
input
1 -1 -2 -1 3 -4 -5
[-1, -2, -1]
...Program finished with exit code 0
Press ENTER to exit console
About · FAQ • Blog • Terms of Use · Contact Us • GDB Tutorial •
Credits · Privacy
© 2016 - 2022 GDB Online
Transcribed Image Text:Run O Debug I Stop E Share A sSave {} Beautify OnlineGDB beta main.py online compiler and debugger for c/c++ 1- def getLongestSeq(a, n): maxIdx = 0 maxLen = 0 currLen = 0 currIdx = 0 for k in range (n): if a[k] < 0: code. compile. run. debug. share. 3 4 IDE My Projects 7- Classroom new 8 currLen +=1 Learn Programming 10 # New sequence, store # beginning index. if currlen == 1: currIdx = k Programming Questions 11 Sign Up 12- 13 Login 14 - else: if currLen > maxLen: maxLen = currLen maxIdx = currIdx currLen = 0 15- fy + 24.8K 16 17 18 19 20- if maxlen > 0: 21 print(a[maxIdx:maxIdx maxLen]) 22- else: 23 print("No negative sequence detected.") 24 25 arr=list(map(int, input().split(" "))) 26 n = len(arr) 27 getLongestSeq(arr, n) input 1 -1 -2 -1 3 -4 -5 [-1, -2, -1] ...Program finished with exit code 0 Press ENTER to exit console About · FAQ • Blog • Terms of Use · Contact Us • GDB Tutorial • Credits · Privacy © 2016 - 2022 GDB Online
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education