Arrays: Left Rotation

  • + 0 comments

    This is a Golang efficient solution:

    func rotLeftEfficient(a []int32, d int32) []int32 {
    	size := int32(len(a))
    	// Ensure d is within range
    	d = d % size
    
    	// Rearranging elements directly
    	return append(a[d:], a[:d]...)
    }