package java_programs;
import java.util.*;

public class FLATTEN {
    public static List<Object> flatten(Object arr) {
        if (arr instanceof List) {
            List<Object> narr = (List<Object>) arr;
            List<Object> result = new ArrayList<>();
            for (Object x : narr) {
                if (x instanceof List) {
                    result.addAll(flatten(x));
                } else {
                    result.add(x);
                }
            }
            return result;
        } else {
            List<Object> singleItemList = new ArrayList<>();
            singleItemList.add(arr);
            return singleItemList;
        }
    }
}