## Program to Print Factorial of a Number in PHP – Iterative & Recursive Approach

Write a program to print factorial of a number in PHP. In this tutorial, We are going to write a PHP code to print factorial of a number using iterative as well as recursive approach. Before solving this problem let’s understand what is factorial.

Program to Print Factorial of a Number in PHP

## C Program to Check whether a Number is Prime or Not

Write a c program to check whether a number is prime or not. Given an integer, We have to write an efficient code to check whether a number is prime or not.

## Find Common Elements in Two Arrays – Intersection of two Arrays

Given two sorted arrays, Write a c code to find common elements in two arrays. In other words, we have to write a code to find the intersection of two arrays.

Let’s assume following two sorted arrays arr1[] and arr2[].

int arr1[] = {2,  3,  4,  5,  6};
int arr2[] = {4,  6,  7,  8,  9};

So the common elements in these two arrays is 4 and 6.

## Generate Prime Numbers between 1 to N – Sieve of Eratosthenes

Write an efficient program to generate prime numbers between 1 to N (Where N is 10, 100, 1000 etc). This question can also be asked like this, Generate prime numbers between 1 to 100 or 1 to 10 etc.

Suppose the value of N is 10, So the prime numbers between 1 to 10 is 2, 3, 5, 7.  Now let’s learn the most efficient algorithm (Sieve of Eratosthenes) to generate Prime Numbers between 1 to N. Before solving this program, let’s understand what is a prime number.

## MCQ on Data Structure – Stack and Queue

MCQ on stack and queue data structure. The concept of Stack and Queue data structure is very important in computer science. In my previous post i have discussed following things.

The purpose of this objective questions is to test how well you understand the concept of stack and queue.

## Program to Search an Element in an Array

Write a program to search an element in an array. Given a sorted array, how do you search an element in an array. Think for a moment how do you solve this problem.

You can use multiple approaches to find the solution of this problem. But try to solve this problem in minimum time complexity.

## Find the Second Largest Number in an Array

Write a program to find the second largest number in an array. Given an unsorted array, we have to write a code to find the second largest number in an array. Also, we need to focus on time complexity. As the time complexity of an algorithm is very important in terms of an interview.

For example – Let’s take an array.

Input – arr[] = { 4, 1, 5, 2, 8, 0, 3, 55}

Output – 8

The second largest element in this array is 8.  Think for a moment, how do you find the second largest number in an array?  There are multiple ways to solve this problem. Which approach you prefer and why?

In this tutorial, we cover following things –

• How to find the second largest number in an array using sorting.
• C program to find the second largest number in an array.
• C++ program to find the second largest number in an array.
• PHP code to find the second largest number in an array.

## PHP Code – Find First Non-Repeated Character in a String

Given an input string, Write a PHP code to find the first Non-repeated character in a string. Suppose an input string is webrewrite, the first non-repeated character in this string is b.

## Program to Delete a Linked List

Write a program to delete a linked list. Given a linked list, we have to write a code to delete a linked list.

To delete a complete linked list, traverse all the nodes of a linked list and delete one by one.

Print Middle Element of a Linked List

## How to Delete a Linked List

To delete a node one by one maintain two pointers.  The first pointer points to head and the second pointer keeps the reference to next node. So when a node is free, you can assign the reference of next node using the second pointer.