CodeKaze

Sponsor

test

Sample Text

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

About & Social

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum viverra pharetra. Nulla facilisis, sapien non pharetra venenatis, tortor erat tempus est, sed accumsan odio ante ac elit. Nulla hendrerit a est vel ornare. Proin eu sapien a sapien dignissim feugiat non eget turpis. Proin at accumsan risus. Pellentesque nunc diam, congue ac lacus

My First Blog Page blog.codingninjas.in Coding Ninja first Blog ...

Search This Blog

Archive

Tags

Post Top Ad

ads

Latest Admit Cards

Beauty

Latest Admissions

Hot

Latest Syllabus

Latest Answer Key

About Us

Recent

Subscribe To Get All The Latest Updates!

email updates

Recent Posts

ads

Post Top Ad

Featured Posts

Log in

Sports

Games

No comments :

My First Blog Page

blog.codingninjas.in

Coding Ninja first Blog

A step-by-step walk through of your first HTML page

HTML is short for HyperText Markup Language.Basically, it’s the “code” behind every webpage – even this one. If you’re just beginning to learn HTML, let us tell you that it’s a fairly easy task. HTML, without styling, can’t do anything more than setting a layout, drawing a table, or creating frames – but it is handy as it helps you structure the content correctly, which is important when you sit down to add style to your HTML.
However simple this might seem, it is a mighty useful tool when it comes to full-fledged web development. Various tools easily eliminate the HTML coding from your work process – but if you want to be in full control of your web-page, you’ll need to have some command over HTML.
Through this article, we aim to give you the essential HTML building blocks that’ll help you get up and running. Reading this, you’ll be able to understand an HTML source code and even modify it for your own good!

Step One - TAGS

Tags are what you’ll see the most when you look at any HTML source code. A tag can ideally be seen as a wrapper to any item on your HTML document. Tags tell what magic is to be done on the content enclosed by them.
Let’s look at two types of tags:
  1. &lttag-example-1&gtI need a closign tag &lttag-example-1&gt
  2. &lttag-example-2/&gt I don't need a cloding tag.
In the first example, the sentence is wrapped by two tags. The first one is called the opening tag and the second one is called the closing tag. Everything in between is affected by the properties of the tag. Very commonly used examples of such tags are &lthtml&gt, &lthead&gt, &ltbody&gt, &ltstrong&gt, etc.
The second example tags about loner tags – as in, they don’t need a closing tag to function. Although it’s not required, these type of tags are often written as &lttag/&gt to make the debugging of code easier. Common examples of such tags are &lthr/&gt – used for horizontal line, &ltbr/&gt – to break the line, etc.

Step Two – HTML, HEAD, and BODY: The three pillars of your document

These tags are essential for any HTML document. They parcel out the significant parts of your HTML code.
  • &ltBODY&gt &lt/BODY&gt is placed below your &ltHEAD&gt tag, and everything that you want to be displayed on your screen comes under this tag. Text, images, links, and pretty much anything you can see in your browser live inside this tag.
  • &ltHTML&gt &lt/HTML&gt wraps your entire code. Everything else in your HTML document needs to come inside these tags.
  • &ltHEAD&gt &lt/HEAD&gt includes things like title, styles, and scripts. Head is usually present at the top (hah!), just inside the &lt/HTML&gt tag.

Step three – A few tags that’ll make your page pretty

Now that you know how to set up the skeleton of your document, let’s proceed with the things that will go inside your &ltBODY&gt tag and do some magic!
Some basic text formatting tags:
  • &ltb&gt &lt/b&gt makes your text look bold
  • &lti&gt &lt/i&gt makes you write in cursive
  • &ltu&gt &lt/u&gt underlines what you just wrote
For example, this piece of code

&lthtml&gt
&lthead&gt &lt/head&gt
&ltbody&gt
&lti&gt I am italics! &lt/i&gt &ltbr/&gt
&ltb&gt I am bold! &lt/b&gt &ltbr/&gt
&ltu&gt And me, well, I'm underlined! &lt/u&gt &ltbr/&gt
&lt/body&gt &lt/html&gt
Should produce something like this on your browser: Don’t fret too much about the
. It’s just for breaking the line so that you can start from the next line. Enter key does little when it comes to changing lines in your HTML document.

Tags to help you structure your content:

  • &ltbr/&gt breaks the line, making you continue to the next line
  • &ltp&gt stands for paragraph. It divides your content into paragraphs

Note: you need to use these tags as space and enter keys do very little when it comes to formatting content inside an HTML document.

Heading Tags:

HTML provides you with six tags, from &ltH1&gt &lt/H1&gt to &ltH6&gt &lt/H6&gt to help you create different sized headers quickly.

  1. &ltH1&gt Heading 1&lt/h1&gt

  2. &ltH2&gt Heading 2&lt/h2&gt

  3. &ltH3&gt Heading 3&lt/h3&gt

  4. &ltH4&gt Heading 4&lt/h4&gt

  5. &ltH5&gt Heading 5&lt/h5&gt
  6. &ltH6&gt Heading 6&lt/h6&gt

Inserting an Image:

All that’s good, but what fun without images on the webpage? Don’t worry, &ltIMG/&gt to the rescue! The image tag has a mandatory attribute called “source”. Basically, it tells the browser where it should look for the image. The syntax goes something like:
&lt img src = “path_to_your_image” /&gt
Furthermore, it also has attributes like height and width that let you specify the height and width you want your image to take.

Lists:

HTML has two types of lists – ordered and unordered. Each item of your list has to be enclosed in a tag. The syntax for creating a list is fairly simple.
Suppose you want to create a list like:
  • Item 1
  • Item 2
  • Item 3
The following code will easily do the job for you:

&ltul&gt
&ltli&gt Item 1 &lt/li&gt
&ltli&gt Item 2 &lt/li&gt
&ltli&gt Item 3 &lt/li&gt
&lt/ul&gt

This, by the way, was an example of an unordered list. For an ordered list, all you need to do is replace &ltul&gt with &ltol\&gt and &lt/ul&gt with &lt/ol&gt.
Let’s see what the following code does:

&lthtml&gt
&lthead&gt &lt/head&gt
&ltbody&gt
&ltu&gt
&ltli&gt I am unordered list's item 1! &lt/li&gt
&ltli&gt I am unordered list's item 2! &lt/li&gt
&ltli&gt I am unordered list's item 3! &lt/li&gt
&ltli&gt I am unordered list's item 4! &lt/li&gt
&lt/ul&gt
&ltol&gt
&ltli&gt I am ordered list's item 1! &lt/li&gt
&ltli&gt I am ordered list's item 2! &lt/li&gt
&ltli&gt I am ordered list's item 3! &lt/li&gt
&ltli&gt I am ordered list's item 4! &lt/li&gt
&lt/ol&gt
&lt/body&gt
&lt/html&gt


All of these tags, when arranged coherently, will provide you with a simple webpage consisting of images, headings, and lists. Further, there are various tags that HTML supports, and we thoroughly recommend you to check them out and play with them!

In Conclusion

You now know enough to skim through and understand any part of an HTML code. We request you to go ahead and try skimming through the source code of any website (you’ll find some tags you don’t know, but that’s how you learn!). Oh, and welcome to the world of web development. With HTML under your belt, your next stop should be making your page look beautiful using CSS.
Let us know if you had any problems in the article, and don’t forget to have a look at a source code or two! -->

Remove Leaf Node Of Binary Tree

No comments :



Problem: Given a binary tree, how do you remove leaves of it?
Solution: By using post-order traversal we can solve this problem (other traversals would also work).
Examples:
Input : 20 10 5 15 30 25 35
Output : Inorder before Deleting the leaf node
         5 10 15 20 25 30 35
         Inorder after Deleting the leaf node
         10 20 30

        This is the binary search tree where we
        want to delete the leaf node.
              20
           /     \
          10      30
         /  \    /  \
       5     15 25   35 

      After deleting the leaf node the binary 
      search tree looks like
              20
           /     \
          10      30
     
public static BinaryTreeNode<Integer> removeLeaf(BinaryTreeNode<Integer> root)
 {
  if(root == null)
  {
   return null;
  }
  
  if(root.left==null && root.right==null)
  {
   return null;
  }
  
  
  BinaryTreeNode<Integer> left = removeLeaf(root.left);
  
  BinaryTreeNode<Integer> right = removeLeaf(root.right);
  
  
  root.left  = left;
  root.right = right;
  
  return root;
 }

Return Keypad Code

No comments :

Given an integer n, using phone keypad find out all the possible strings that can be made using digits of input n.

Return empty string for numbers 0 and 1.

Note : The order of strings are not important.
Input Format :
Integer n
Output Format :
All possible strings in different lines
Constraints :

1 <= n <= 10^6

Sample Input:
23
Sample Output:
ad
ae
af
bd
be
bf
cd
ce
cf





public class key {
 
 static String[] code = {"","abc","def","ghi","jkl","mno","pqr","st","uvwx","yz"};
 
 public static String[] combinaton(int n)
 {
  if(n==0)
  {
   String[] re = new String[1];
   
   re[0] = "";
   return re;
  }
  
  
  String ch = code[n%10];
  
  String[] rr = combinaton(n/10);
  
  String[] mr = new String[rr.length*ch.length()];
  
  int k=0;
  
  for(int i=0;i<rr.length;i++)
  {
   for(int j=0;j<ch.length();j++)
   {
    mr[k] = ch.charAt(j)+rr[i];
    k++;
   }
  }
  
  return mr;
  
  
  
 }
In the second method we have only used Array List 
public class combination {
 
 static String codes[] = {"","abc","def","ghi","jkl","mno","pqr","st","uvwx","yz"};
 
 public static ArrayList<String> com(String str)
 {
  if(str.length()==0)
  {
   ArrayList<String> ans = new ArrayList<>();
   ans.add("");
   return ans;
   
  }
  
  
  char ch = str.charAt(0);
  
  
  ArrayList<String> rr = com(str.substring(1));
  
  ArrayList<String> my = new ArrayList<>();
  
  for(String i:rr)
  {
   String code = codes[ch-'0'];
   
   for(int j=0;j<code.length();j++)
   {
    char c = code.charAt(j);
    
    my.add(c+i);
   }
  }
  return my;
 }
 
 

Quick Sort Code

No comments :

Sort an array A using Quick Sort.

Change in the input array itself. So no need to return or print anything.

Input format :
Line 1 : Integer n i.e. Array size
Line 2 : Array elements (separated by space)
Output format :
Array elements in increasing order (separated by space)
Constraints :

1 <= n <= 1000

Sample Input:
6 
2 6 8 5 4 3
Sample Output:
2 3 4 5 6 8
Like Merge Sort, QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of quickSort that pick pivot in different ways.
  1. Always pick first element as pivot.
  2. Always pick last element as pivot (implemented below)
  3. Pick a random element as pivot.
  4. Pick median as pivot.
The key process in quickSort is partition(). Target of partitions is, given an array and an element x of array as pivot, put x at its correct position in sorted array and put all smaller elements (smaller than x) before x, and put all greater elements (greater than x) after x. All this should be done in linear time.


public class Solution {
    
    
    private static int findIndex(int[] input,int low,int high,int pivot)
    {
        int pI = low;
        
        int itr=low;
            
            while(itr<=high)
            {
                if(input[itr]<=pivot)
                {
                    int temp = input[itr];
                    
                    input[itr] = input[pI];
                    input[pI] = temp;
                    
                    itr++;
                    pI++;
                }
                else
                {
                    itr++;
                }
            }
        
        return pI-1;
    }
    
    private static void quickSort(int[] input,int low ,int high)
    {
        if(low>=high)
        {
            return;
        }
        
        
        int pivot = input[high];
        
        int pivotIndex = findIndex(input,low,high,pivot);
        
        
        quickSort(input,low,pivotIndex-1);
        
        quickSort(input,pivotIndex +1,high);
    }
 
 public static void quickSort(int[] input) {
        
        int low =0;
        int high = input.length-1;
        
        quickSort(input,low,high);
  
  
 }
 
}

Pair star

No comments :

Given a string, compute recursively a new string where identical chars that are adjacent in the original string are separated from each other by a "*".

Sample Input 1 :
hello
Sample Output 1:
hel*lo
Sample Input 2 :
xxyy
Sample Output 2:
x*xy*y
Sample Input 3 :
aaaa
Sample Output 3:
a*a*a*a
public class solution {

 // Return the updated string
 public static String addStars(String s) {
  // Write your code here
        
          if(s.length()<=1)
  {
   return s;
  }
  
  
        
        String ans = "";
        
        if(s.charAt(0)==s.charAt(1))
        {
         ans= ans+s.charAt(0)+'*';
         
         
        }
        else {
         ans = ans+s.charAt(0);
        }
     
        
        String str = addStars(s.substring(1));
        
        return ans+str;

 }
}