algorithm solve this task in 2 way and calculate the time complexity

enter image description here
write pseudo code and calculate the complexity .and write it in coding with c or java language and calculate the complexity .and show what the better