Same solution Accepted on Leetcode, runtime error on Interview Bit


Now i have started hating this platform
whenever i use recursion in Linked list type of problems its giving me stack overflow error, The same solution gave me 0 ms runtime and faster than 100% java submissions on leetcode, but here its giving me runtime error
Please Please increase the heap size of your java runtime, there are people who are fan of recursion
my solution
private ListNode rotatedListNodePtr = null;
private int counterVal = 0;
private int pivotPoint = -1;
public ListNode rotateRight(ListNode A, int B) {
pivotPoint = B;
if(A == null)
return null;
ListNode ptr = rotateList(A, 0);
if(ptr == null)
return rotatedListNodePtr;

if(rotatedListNodePtr == null)
return ptr;

ListNode start = rotatedListNodePtr;
while ( != null)
start =; = ptr;
return rotatedListNodePtr;

private ListNode rotateList(ListNode node, int len){
if(node == null){
if(pivotPoint > len)
pivotPoint = pivotPoint%len;
return null;
} = rotateList(, len+1);
if(counterVal == pivotPoint){
rotatedListNodePtr = node;
return null;
return node;