Rotating array is not working in Leetcode /u/Professional-Egg-788 Python Education

Hey everyone, I am trying coding in leetcode. I am stuck in Rotate Array problem. I have to rotate the list to the number of times the the value of k. I did this kind of problem during my training period and it got passed. I used similar logic here as well the list is rotating correctly but it is not showing the output. I am not getting why. Please help me to understand the issue here.

class Solution(object): def rotate(self, nums, k): n=len(nums) k%=n count=0 s=0 while count<k: s=nums[-1] #print(s) nums=nums[:-1] nums.insert(0,s) count+=1 print(nums) return nums Here's the Input: nums =[1,2,3,4,5,6,7] value of k=3 Here's the stdoutput: [5, 6, 7, 1, 2, 3, 4] Actual output showing: [1,2,3,4,5,6,7] required output: [5,6,7,1,2,3,4] 

submitted by /u/Professional-Egg-788
[link] [comments]

​r/learnpython Hey everyone, I am trying coding in leetcode. I am stuck in Rotate Array problem. I have to rotate the list to the number of times the the value of k. I did this kind of problem during my training period and it got passed. I used similar logic here as well the list is rotating correctly but it is not showing the output. I am not getting why. Please help me to understand the issue here. class Solution(object): def rotate(self, nums, k): n=len(nums) k%=n count=0 s=0 while count<k: s=nums[-1] #print(s) nums=nums[:-1] nums.insert(0,s) count+=1 print(nums) return nums Here’s the Input: nums =[1,2,3,4,5,6,7] value of k=3 Here’s the stdoutput: [5, 6, 7, 1, 2, 3, 4] Actual output showing: [1,2,3,4,5,6,7] required output: [5,6,7,1,2,3,4] submitted by /u/Professional-Egg-788 [link] [comments] 

Hey everyone, I am trying coding in leetcode. I am stuck in Rotate Array problem. I have to rotate the list to the number of times the the value of k. I did this kind of problem during my training period and it got passed. I used similar logic here as well the list is rotating correctly but it is not showing the output. I am not getting why. Please help me to understand the issue here.

class Solution(object): def rotate(self, nums, k): n=len(nums) k%=n count=0 s=0 while count<k: s=nums[-1] #print(s) nums=nums[:-1] nums.insert(0,s) count+=1 print(nums) return nums Here's the Input: nums =[1,2,3,4,5,6,7] value of k=3 Here's the stdoutput: [5, 6, 7, 1, 2, 3, 4] Actual output showing: [1,2,3,4,5,6,7] required output: [5,6,7,1,2,3,4] 

submitted by /u/Professional-Egg-788
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *