0

Pls help me i doesn't have any idea

Given a string which is sorted in non-increasing order return the number of negative numbers. Input Format The input format is string separated with special character '#' and spaces Constraints none Output Format The output format is number Sample Input 0 4 3 2 -1#3 2 1 -1#1 1 -1 -2#-1 -1 -2 -3 Sample Output 0 8 Explanation 0 Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]] Output: 8 Explanation: There are 8 negatives number in the matrix. Sample Input 1 3 2#1 0 Sample Output 1 0 Explanation 1 Input: grid = [[3,2],[1,0]] Output: 0

17th Nov 2022, 4:38 PM
Rajeshwari. S
Rajeshwari. S - avatar
5 Answers
+ 3
Prepare a counter variable, let's juat name it <negatives> Split the string by #. By then you'd have a `list` with 4 elements Next split each element from that `list` by space, into a temporary `list`, and try to convert each element from the temporary `list` into an integer In case conversion succeeded, check whether the converted integer was negative, increment <negatives> when it is.
17th Nov 2022, 4:54 PM
Ipang
+ 3
But how you learn if I give you the code? the mission of SoloLearn was about learning by one self ... Why you attempted this? I see you haven't started Python here ...
17th Nov 2022, 5:00 PM
Ipang
+ 2
Accept input and split it by #. You will get a list. Again by a loop, each value from list split again by space. You get list of numbers in str form. Convert each by int() and check if negative! If negative increase counter. Else do nothing. Finally after loop print counter value. So read about input() , split() , int() functions, for loop, if condition. Each takes a 3mins i think. You can solve it.
17th Nov 2022, 6:20 PM
Jayakrishna 🇼🇳
+ 1
Pls give me a proper code then I will understand step by step
17th Nov 2022, 4:55 PM
Rajeshwari. S
Rajeshwari. S - avatar
+ 1
Yeah I started learning basics only. I need a solution for this . So pls send me the code.
17th Nov 2022, 5:03 PM
Rajeshwari. S
Rajeshwari. S - avatar