General conditions for maximal violation of non-contextuality in discrete and continuous variables uri icon