#!/bin/python3 import math import os import random import re import sys # # Complete the 'getOneBits' function below. # # The function is expected to return an INTEGER_ARRAY. # The function accepts INTEGER n as parameter. # def getOneBits ( n ): # Write your code here if n == 0 : return [ 0 ] binary = bin ( n )[ 2 :] d = [] pos = 1 temp = n for idx , bit in enumerate ( binary , 1 ) : if bit == '1' : d . append ( idx ) return [ len ( d )] + d if __name__ == '__main__' : fptr = open ( os . environ [ 'OUTPUT_PATH' ], 'w' ) n = int ( input () . strip ()) result = getOneBits ( n ) fptr ...
coderEdge
Learn programming, data structures, and algorithms on CoderEdge with simple tutorials, coding examples, and guides for students and developers.