Optimized solution using transformation function