0

Delete a slice

Dwight has given you a list with some integers. In this list, there is a bad series. The bad series starts from the beginning and spans up till the A[0]th index. Example: for [1,0,4,7] the bad series is [1,0] spanning up till 1st index Therefore, the desired list is [4, 7] for [2,1,5,8,9], the bad series is [2,1,5] spanning up till the 2nd index Therefor, the desired list is [8,9] Complete the given method solve which takes as parameter a list A and returns A such that the bad series is removed

17th Oct 2021, 2:03 PM
Gopi Satya Sivakumar
Gopi Satya Sivakumar - avatar
6 Réponses
+ 6
Gopi Satya Sivakumar , can you show us your attempt please?
17th Oct 2021, 7:15 PM
Lothar
Lothar - avatar
+ 3
I don’t get it how do u know the bad series?
17th Oct 2021, 5:28 PM
ubai
ubai - avatar
+ 3
Gopi Satya Sivakumar , if understand you correctly, it can be done like # these are the lists mentioned: lst = [2,1,5,8,9] bad = [2,1,5] ▪︎use a for loop and iterate through the 'bad' list ▪︎use each number you get there, and remove it in the 'lst' list ▪︎print the 'lst' list the result is: [8, 9] this is just 3 lines of code
17th Oct 2021, 7:26 PM
Lothar
Lothar - avatar
0
I Did Like This And Got Only Two Cases Passed.Another Test Case Didn't Pass.How Will It Can Be Passed? def solve(A): n = A[0] if(len(A) % 2 == 0): del A[:n+1] return A else: A = A[-n:] return A
18th Oct 2021, 2:05 AM
Gopi Satya Sivakumar
Gopi Satya Sivakumar - avatar
0
2nd test case worng
9th Oct 2022, 7:23 AM
kanakaraju P
kanakaraju P - avatar
0
def solve(A): # write your code here n=len(A) i=A[0] if n%2==0: del A[:i+1] else: A=A[1+i:] return A
12th Jan 2023, 5:50 AM
PONNA LOKESH KUMAR