Symantec Interview Question for Senior Software Development Engineers


Country: India
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
1
of 1 vote

class iterator{
     int * m_ptr;
     int m_data;
     iterator(int a[], int idx){
       m_ptr = &a[idx];
       m_data = a[idx];
    }
    iterator(const iterator & x){
       m_ptr = x.m_ptr;
       m_data = x.m_data;
    }
    void increment(){m_data = *(++m_ptr);}
    void decrement() {m_data = *(--m_ptr);}
    int & operator *() const {return *m_ptr;}
    int * operator->() const {return &(operator) *()}
    iterator & operator ++ () {increment(); return *this}
    iterator & operator --() {decrement(); return *this}
    iterator & operator ++(int) {iterator tmp = *this; increment(); return tmp;}
    iterator & operator --(int) {iterator tmp = *this; decrement(); return tmp;}
    friend bool operator=(const iterator & ld, const iterator & rd){
        return ld.m_ptr == rd.m_ptr;
     }
    friend bool operator != (const iterator & ld, const iterator & ld){
       return ld.m_ptr != rd.m_ptr;  
   }
  }

- iterator for int array April 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

What does the question even mean?

- Anonymous April 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class Pract {
public static void main(String[] args) {

int[] ar=new int[3];
ArrayList<Integer> arr=new ArrayList<Integer>(3);
ar[0]=63;
ar[1]=43;
ar[2]=33;
arr.add(5);
arr.add(6);
arr.add(3);
Iterator it=arr.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
for(int i:ar)
{
System.out.println(i);
}
}

}

- Onkar August 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

File Array.h

#ifndef __ARRAY_H_
#define __ARRAY_H_

#include "ArrayIteartor.h"

template <class T, int SIZE>
class Array
{
    typedef ArrayIterator<T> iterator;
    public:
        Array(int size=SIZE):m_size(size)
        {
            m_data = new (nothrow) T[m_size];
            if(!m_data)
            {
                cout<<"Memory allocation error."<<endl;
            }
        }
        Array(const Array<T>& rhs)
        {
            if (rhs.m_size)
            {
                m_data = new (nothrow) T[rhs.m_size];
                if (!m_data)
                {
                    cout<<"Memory allocation error."<<endl;
                }
                iterator iter1 = rhs.begin();
                int i=0;
                while(iter1 != rhs.end())
                {
                    m_data[i] = *iter1;
                    ++iter1;
                }
            }
        }
        iterator begin()
        {
            iterator it(&m_data[0]);
            return it;
        }
        iterator end()
        {
            iterator it(&m_data[m_size-1]);
            return it;
        }
    private:
        int* m_data;
        int m_size;
};
#endif

File ArrayIterator.h

#ifndef __ARRAY_ITERATOR_H_
#define __ARRAY_ITERATOR_H_

template <class T>
class ArrayIterator;    


template <class T>
bool operator!=(const ArrayIteartor<T>& first, const ArrayIterator<T>& second);

template <class T>
bool operator==(const ArrayIteartor<T>& first, const ArrayIterator<T>& second);

    
template <class T>
class ArrayIterator
{
    public:
        ArrayIterator(T* ptr=NULL):m_ptr(ptr)
        {
        }
        ArrayIterator(const ArrayIterator& x):m_ptr(x.m_ptr)
        {
        }
        ArrayIterator& operator++()
        {
            ++m_ptr;
        }
        ArrayIterator operator++(int)
        {
            ArrayIterator<T> temp(*this);
            ++m_ptr;
            return temp;
        }
        ArrayIterator& operator--()
        {
            --m_ptr;
        }
        ArrayIterator operator--(int)
        {
            ArrayIterator<T> temp(*this);
            --m_ptr;
            return temp;
        }
        T* operator->()
        {
            return m_ptr;
        }
        T& operator*()
        {
            return *m_ptr;
        }
        friend bool operator!= <>(const ArrayIterator<T>& first, const ArrayIterator<T>& second);
        friend bool operator== <>(const ArrayIterator<T>& first, const ArrayIterator<T>& second);
    private:
        T* m_ptr;
};

template <class T>
bool operator==(const ArrayIterator<T>& first, const ArrayIterator<T>& second)
{
    return (first.m_ptr == second.m_ptr);
}

template <class T>
bool operator!=(const ArrayIterator<T>& first, const ArrayIterator<T>& second)
{
    return (first.m_ptr != second.m_ptr);
}


#endif

- Jitendra Singh Bhadoriya September 26, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More