Arrays: Left Rotation

  • + 5 comments

    In java8 the problem was in String; You have to use more efficient StringBuilder instead; And of couse use only one loop to iterate over array;

    here is my code snippet:

    StringBuilder output = new StringBuilder();
    	
    	for(int i = 0; i<n; i++) {
    		
    		b[i] = a[(i+k) % n];
    		output = output.append(b[i]).append(" ");
    		
    	}