# 05.04.2026 [657. Robot Return to Origin]
R,L,U,D return to 0 in XY plane #easy
05.04.2026
Join me on Telegram
Problem TLDR
R,L,U,D return to 0 in XY plane #easy
Intuition
Compare counts separately for vertical and horizontal directions. Both directions can fit into a single variable h*2^16+v.
Approach
hash collisions of 8 make the solution extra spicy
do you know how %5 works?
Complexity
Time complexity: $$O(n)$$
Space complexity: $$O(1)$$
Code
// 38ms
fun judgeCircle(m: String) =
0==m.sumOf {listOf(8,-1,1,-8)[it.code%5]}
// 0ms
pub fn judge_circle(m: String) -> bool {
0==m.bytes().fold(0,|a,b|a+[8,-1,1,-8][(b%5)as usize])
}


