Thursday, 21 January 2016

STL arrays example

// constructing arrays
#include <iostream>
#include <array>

// default initialization (non-local = static storage):
std::array<int,3> global;               // zero-initialized: {0,0,0}

int main ()
{
  // default initialization (local = automatic storage):
  std::array<int,3> first;              // uninitialized:    {?,?,?}

  // initializer-list initializations:
  std::array<int,3> second = {10,20};   // initialized as:   {10,20,0}
  std::array<int,3> third = {1,2,3};    // initialized as:   {1,2,3}

  // copy initialization:
  std::array<int,3> fourth = third;     // copy:             {1,2,3}

  std::cout << "The contents of fourth are:";
  for (auto x:fourth) std::cout << ' ' << x;
    std::cout << '\n';

  return 0;
}

STL list example

#include <iostream>
#include <list>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
        int array[] = {9,8,7,9, 6, 5,1,2,3,4,1,2,5};

        //Initialize
        list<int> l(array, array + sizeof(array)/sizeof(array[0]));
        list<int> l2;
        l2.assign(array, array + sizeof(array)/sizeof(array[0]));

        list<int>::iterator it = l.end();

        vector<int> v(3,30);

        //Insert
        l.insert(it, 10);
        l.insert(it, 2, 20);
        l.insert(it, v.begin(), v.end());
        l2.push_back(10);

        //Delete
        l.erase(l.begin());
        l2.erase(l2.begin(), l2.begin()++);

        //Search
        list<int>::iterator it1 = find(l.begin(), l.end(), 7);
        cout<<"Found: "<<*it1<<endl;

        //Traverse
        for(list<int>::iterator it = l.begin(); it != l.end(); it++)
                cout<<*it<<" ";
        cout<<endl;
        for(list<int>::iterator it = l2.begin(); it != l2.end(); it++)
                cout<<*it<<" ";
        cout<<endl;

        //Clear
        l.clear();
}

Friday, 11 December 2015

New PC windows 8.1

Get the product key:
http://www.isunshare.com/product-key-finder/find-product-key-for-windows-8-or-8.1.html

Default antivirus for windows 8.1:(Windows Defender)
http://windows.microsoft.com/en-in/windows/using-defender#1TC=windows-7
http://windows.microsoft.com/en-in/windows/turn-windows-defender-on-off#turn-windows-defender-on-off=windows-7
To remove: http://www.sysprobs.com/how-to-remove-windows-defender-on-windows-8-1-windows-8
Install: https://www.avast.com/index
Avast key for 26 years: W3083976R9962A0912-ZZT6LA5J
If the trial version is going to expire: http://peterbestel.com/help/how-to-re-register-avast-free-anti-virus/

User accounts:
http://windows.microsoft.com/en-in/windows/turn-user-account-control-on-off#1TC=windows-7
http://windows.microsoft.com/en-in/windows/create-user-account#create-user-account=windows-7
http://www.softwareok.com/?seite=faq-Windows-8&faq=57

Exporting contacts:
http://answers.microsoft.com/en-us/mobiledevices/wiki/mdlumia-mdtips/how-to-export-contacts-from-windows-phone-to-pc/e6f8292c-8081-45d6-a40d-7ff2337b8a41

Sunday, 4 October 2015

iOs app development xcode6 and swift

Creating tabs:
https://www.youtube.com/watch?v=d1_X0DQdY8o

Dropdown menu:
https://www.youtube.com/watch?v=aj92JFosapk

Creating slider:
https://www.youtube.com/watch?v=jJA9UCbcos0

Sample code fo JSON:
--------------------------
import Foundation

var error: NSError?
//let jsonData: NSData = /* get your json data */
let jsonData = NSData.dataWithContentsOfFile(filepath, options: .DataReadingMappedIfSafe, error: nil)

let jsonDict = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &error) as NSDictionary

Horizantal scrolling:
------------------------
http://www.raywenderlich.com/4723/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-2
http://devblog.orgsync.com/2013/04/26/creating_scrolling_filmstrip_within_uitableview/
http://www.brianjcoleman.com/tutorial-collection-view-using-swift/
http://www.appcoda.com/uiscrollview-introduction/



Table view:
https://www.youtube.com/watch?v=pR6dR-vVZeY

Custom cell:
http://stackoverflow.com/questions/25999759/custom-table-view-cell-with-swift-in-xcode-6

Adding image to cell:
http://stackoverflow.com/questions/24094644/adding-an-image-into-a-cell

Segue from UIImage to view controller:
http://stackoverflow.com/questions/28647242/segue-ui-image-to-viewcontroller-with-swift

Table view example:
http://www.theappguruz.com/blog/ios-table-view-tutorial-using-swift

Create popover:
https://www.youtube.com/watch?v=j5XFMpXLwZQ

Suggested by Vignesh:
https://developer.apple.com/library/ios/documentation/ToolsLanguages/Conceptual/Xcode_Overview/DesigningwithStoryboards.html#//apple_ref/doc/uid/TP40010215-CH43-SW1


http://makeapppie.com/2014/08/04/the-swift-swift-tutorial-why-do-we-need-delegates/#comment-15424
http://stackoverflow.com/questions/12993212/segmented-control-on-top-of-a-table-view-not-in-the-title-view-though


layer.cornerRadius          Number    10
layer.masksToBounds     Boolean    tick

popover:
----------
http://stackoverflow.com/questions/27353691/uipopoverpresentationcontroller-displaying-popover-as-full-screen

Exporting app:
------------------
http://bouk.co/blog/sideload-iphone/
http://www.idownloadblog.com/2015/09/18/how-to-compile-apps-using-xcode-7-to-run-on-a-non-jailbroken-device/



Tuesday, 22 September 2015

Answers

Power set of given set:
    http://www.geeksforgeeks.org/power-set/

Monday, 21 September 2015

Interview questions

Amazon:
----------
1) Given a rotated sorted array, find the first occurrence of a certain number X with the lowest possible complexity(both time and space).

X = 6
Arr = 8,9,9,1,3,4,4,4,6,6,7,7

Ans = 8

2) Given a linked like defined so...

typedef node_t {
int data;
node_t* next;
}Node;

check if the linked list is a palindrome without using any extra space and with the lowest possible complexity(both time and space).

write code for following API

BOOL is_palindrome(node *Head);

3) write an algorithm to find the next largest node in a binary tree.

typedef treenode_t{
int data;
treenode_t *parent;
treenode_t *left;
treenode_t *right;
}TreeNode;

TreeNode* find_next_largest_element(TreeNode *node);

Written:
  • Program to find the run length encoding of a string.
  • Program to check whether there exists a root to leaf path having a given sum in a binary tree.

Round 1:
  • Program to implement an LRU cache.
  • Program to convert a sorted array to balanced binary search tree.
  • Program to reverse a single linked list in groups of k recursively.
  • Design a data structure for implementing dictionary.

Round 2:
  • Program to recursively calculate a^n.
  • Design a data structure for an infinite stream of numbers such that it's optimized for insertion, deletion, searching, finding kth largest and kth smallest.
1. Given a BST and 2 numbers a,b. Find the number of hops to reach from a to b. 

2. Given a set of unsorted numbers without a range, find the median. No sort operations should be used. Solution should be of the order n log n.

written: 
1. convert sorted array to BST
2. next larger number in a given array for an index
3. find first non-repeative char in a string

interview:
1. find longest path in a tree
2. implement dictionary

Microsoft : 
------------
a) Write a function which simply returns 0X00000000 if input value is 0 else 0XFFFFFFFF. Condition is no branching , no looping and no ternary operators.
Solutions
1
2
3
4
int bit(int n)
{
return (!n + (n|~n));
}

b) Infinite bit stream is coming (one bit at a time). At a given time tell whether number is divisible by 3 or not
Solution:
1
2
3
4
5
6
7
8
9
sum=0;
while(bit stream is coming)
{
sum=sum<<1+1*(current bit);
if(sum%3==0)
printf(“divisible\n”);
else
printf(“not divisible”);
}

c) Check whether a given string consists the substring of type “ab*c”
Solution:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
char *str=INPUT STRING
int i=0,flag=0;
while(str[i])
{
if(str[i++]==’a’)
{
while(str[i]==’b’)
i++;
if(str[i++]==’c’)
{
printf(“substring found”);
flag=1;
break;
}
}
}
if(!flag)
printf(“substring not found”);

Written:
  • Program to rotate a matrix by 90 degree counter clockwise in place.
  • Program to sort a single linked list containing only 0s, 1s and 2s.
  • Program to correct a binary search tree in which only any two nodes have been swapped.

Round 1:
  • Given two sorted arrays, find the (set) difference of two.
  • Routine to output the elements of the inorder traversal of a binary tree one by one on its each call.

Round 2:
  • Given a set of courses along with the prerequisite courses for these courses, write a program to find the minimum number of semesters required to wrap up all the courses.


Suggested:
------------
Books : Programming Interviews Exposed
Lectures : Algorithms Lectures on Youtube from MIT
Sites: Careercup,GeeksForGeeks,Leetcode.com

More questions can be found at:
1. http://www.thelearningpoint.net/computer-science/programming-interview-questions---microsoft-amazon-google-facebook
2. http://ashayraut.wordpress.com/interview-preparation-best-100/