Online IDE
Free Mock
Improve your coding skills with our resources
Compete in popular contests with top coders
Explore Offerings by SCALER

Welcome to Interviewbit, help us create the best experience for you!

Currently, You are a:

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your career...

Current Company *
Enter company name
Experience *

You're all set!

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *


Go to Problems

Level 1

Jump to Level 2

Level 2

Jump to Level 3

Level 3

Jump to Level 4

Level 4

Jump to Level 5

Level 5

Jump to Level 6

Level 6

Jump to Level 7

Level 7

Jump to Level 8

Level 8

Be a Code Ninja!

Array Implementation Details

C :
Array declaration :
    int A[1000]; // creates an integer array of size 1000. 
    int *A = (int *) malloc(1000 * sizeof(int)); // creates an integer array of size 1000
Accessing ith element :
C++ :

C style arrays work in C++ as well.

However, C++ provides vectors which is much more powerful than C arrays. We will be using C++ vectors in most of the problems on this judge.

Vector declaration :
    vector<int> V; // declares an empty integer array of size 0. O(1) 
    vector<int> V(100, 1); // declares an integer array of size 100 with all elements initialized to 1. O(size)
Accessing ith element :
    V[i] // O(1)
Size ( number of elements ) of the vector :
    V.size()  // O(1)
Adding element to the vector :
    V.push_back(new_value); // new_value will be appended to the vector.  O(1)
Removing element from end of the vector :
    V.pop_back(); // equivalent to size--; O(1)

Java has multiple ways of representing arrays. For the purpose of problem solving on this site, we will limit ourselves to ArrayList.

Array declaration :
    ArrayList<Integer> A = new ArrayList<Integer>(); // declares an empty integer array. O(1)
    ArrayList<Integer> A = new ArrayList<Integer>(B); // creates a copy of list B.  O(size of B)
Accessing ith element :
    A.get(i)     // O(1)
Setting ith element :
    A.set(i, newValue)  // O(1)
Size of the list :
    A.size()  // O(1) operation
Adding elements to the list :
    A.add(newValue); // appends to the end of the list. O(1) operation. 
    A.add(index, newValue); // add the value at specified index. O(size - index) operation. 

Python too has multiple ways of representing arrays. lists are used primarily for the purpose. In few cases, tuples are used when we desire the array to be immutable ( its desired that no one can change the content of the array ).

List declaration :
    A = []; # declares an empty list. O(1)
Accessing the ith element :
    A[i]  # O(1)
Adding element to the list :
    A.append(newValue); # O(1) 
Size of the list :
    len(A)  # O(1) 

Walkthrough example :

Serious about Learning Programming ?

Learn this and a lot more with Scaler Academy's industry vetted curriculum which covers Data Structures & Algorithms in depth.

Arrays Problems

Free Mock Assessment
Help us know you better for the best experience
Current Employer *
Enter company name
College you graduated from *
Enter university name
Phone Number *
OTP will be sent to this number for verification
Change Number
Resend OTP
By Continuing I agree to be contacted by Scaler in the future.
Already have an account? Log in