1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
/* Below global variable is declared in code for modulo arithmetic const long long unsigned int MOD = 1000000007; */ /* Link list Node/ struct Node { bool data; // NOTE data is bool struct Node* next; }; */ // Should return decimal equivalent modulo 1000000007 of binary linked list long long unsigned int decimalValue(struct Node *head) { // Your Code Here int cnt=-1; long long MOD=1000000007; Node *tmp=head; bool arr[200]; while(tmp) { cnt+=1; arr[cnt]=tmp->data; tmp=tmp->next; } long long mult=1; long long res; if(arr[cnt]) res=1; else res=0; if(cnt>0) for(int i=cnt-1;i>=0;i--) { mult=(mult*2)%MOD; mult%=MOD; if(arr[i]) res=(res+mult)%MOD; } return res; } |