Showing posts with label amazon. Show all posts
Showing posts with label amazon. Show all posts

April 28, 2020

Create a simple Tree data structure in Java from an array of values

Tree is a data Structure to create a hierarchical structure


Creating a Node class



/**
 * Node in Tree
 */
package com.cfed.datastructures;

/**
 * @author Konzernites
 *
 */
public class Node {

private int data;
private Node left;
private Node right;

public Node(int data) {
this.data = data;
this.left = null;
this.right = null;
}

public String toString() {
return "data is "+data;
}

public int getData() {
return data;
}

public void setData(int data) {
this.data = data;
}

public Node getLeft() {
return left;
}

public void setLeft(Node left) {
this.left = left;
}

public Node getRight() {
return right;
}

public void setRight(Node right) {
this.right = right;
}
}


Adding  values to a tree



/**
 * Adding values to tree
 */
package com.cfed.datastructures;

/**
 * @author Konzernites
 *
 */
public class BinaryTree {

private Node root;

private Node addRecursion(Node current, int data) {
if (null == current) {
return new Node(data);
} else if( null == current.getLeft()) {
current.setLeft(addRecursion(current.getLeft(), data));
}else if(null == current.getRight()) {
current.setRight(addRecursion(current.getRight(), data));
}else {
addRecursion(current.getLeft(), data);
}
return current;
}

public void addData(int value) {
root = addRecursion(root, value);
}
}


Mainclass.java the entry class


/**
 *  Entry point of the program
 */
package com.cfed.datastructures;

/**
 * @author Athul Ramesh
 *
 */
public class TreeTesting {

public static void main(String[] args) {
int arr[] = {8,6,7,4,3,1,2};
BinaryTree binary = new BinaryTree();
for(int i =0; i< arr.length; i++) {
binary.addData(arr[i]);
}
}
}


You can use this program to store data in a hierarchical structure.

November 21, 2019

Tic Tac Toe algorithm and source code in python

Tic Tac Toe algorithm and source code in python

After a short break, This the first program I wrote in python

n=3#int(input("Enter size of board! "))

def printbox(lst):
    for i in range(2*n+1):
        if i%2==0:
            for k in range(n):
                if k==0:
                    print('  ', end='')
                print('----  ', end='')
        else:
            for k in range(n+1):
                if k==n:
                    print(' |', end='')
                else:
                    pp = addcolor(lst[(i-1)/2,k])
                    print(' |',pp, end='')
        print('')

def addcolor(num):
    if num == 1:
        return '\033[0;37;41m '+str(num)+'\033[0m'
    elif num==2:
        return '\033[0;37;46m '+str(num)+'\033[0m'
    return num

import numpy as np
#strlst = '1,0,1,2,1,1,0,2,1'#input("give 9 numbers")
lst=np.zeros(9).reshape(3,3)

def iswinner(lst):
    printbox(lst)
    
    issame=True
    knum=0
    for i in range(3):
        if np.all(lst[i,:]==1) or np.all(lst[:,i]==1):
            return(1)
        elif np.all(lst[i,:]==2) or np.all(lst[:,i]==2):
            return 2
        if i==0:
            knum=lst[i,i]
        elif issame and knum!=lst[i,i]:
            issame=False
    if issame and knum!=0:
        return knum
    return 0

s=0
while s<9:
    strlst1 = input('your move i,j,number')
    i,j,knum=strlst1.split(',')
    if (s%2==0 and int(knum)==1) or (s%2==1 and int(knum)==2):
        lst[i,j]=knum
        iswin = iswinner(lst)
        if iswin == 1:
            print('1 is winner')
            break
        elif iswin==2:
            print('2 is winner')
            break
        else:
            print('no win')
        s+=1
    else:
        print('enter valid number')



paste code in 
and run





Developed by steffi thomas

May 29, 2019

Best toys for children and Kids

Best toy for Kids for age between 5 ,6 ,7 ,8 ,9 & 10


Children brain are rapidly growing and changing.

These years are critical for brain development , focus and cognitive skills

Toys which sparks the imagination of child while providing interactive play.

They are also great for imaginative play.

Helps the children to think in different possible ways.

Always choose toys that allows baby to explore and interact.

These are our suggestions...






Here is an article showing how do puzzles help the brain




May 16, 2019

One Plus 7 with discount price hurry Offers benefits worth Rs 9300


  • For Prime members only: Upto Rs.2000 Instant Discount with SBI Debit and Credit Cards (excluding RuPay). For Prime customers only
  • No Cost EMI available on major credit cards, select debit cards, Bajaj Finserv EMI card and Amazon Pay EMI. 
  • No cost EMI available on Amazon Pay ICICI credit card on orders above Rs.3000.
  • Up to ₹ 8,000.00 off on Exchange
  • Avail up to 70% Guaranteed Exchange Price, powered by Servify
  • Jio OnePlus Beyond Speed Offer - avail benefits worth Rs 9300
  • Gift Card Pre-book Offer valid till 31st May, 2019: applicable to customers who purchased Rs 1000 OnePlus 7 Pro gift card between 3rd to 7th of May, 2019
  • Up to ₹ 8,000.00 off on Exchange
  • The latest renders of the OnePlus 7 reveal identical design to the OnePlus 6T with a waterdrop notch. The phone has a dual rear camera setup. See More
  • The latest CAD renders for the OnePlus 7 reveal that the phone would have a waterdrop notch and miss out on the pop-up selfie camera design and triple camera setup on the rear. 


OnePlus 6T another best phone in market with affordable rate

8 GB RAM & 64 GB internal memory ...


April 30, 2019

Best Budget smartphone for 10000

If you are planning to buy smart phone here are my option

Mi A2 : A good camera phone for budgeted users, with stock android ( very fast one)

A stylish case

World best ear phone makers sennheiser..  the quality of sound is awesome





January 01, 2019

How to handle NumberFormatException: For input string: "0.0"

How to handle NumberFormatException: For input string: "0.0"


Here is the solution for that problem ( Use BigDecimal instead of Long.parseLong())

/**
 * Exception in thread "main" java.lang.NumberFormatException: For input string: "0.0"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at com.konzern.solution.StringToNumber.main(StringToNumber.java:18)
 */
package com.konzern.solution;

import java.math.BigDecimal;

/**
 * @author cfed
 *
 */
public class StringToNumber {

/**
* @param
*/
public static void main(String[] args) {

/* String valueInString = "0.0";
long valueInLong = Long.parseLong(valueInString);
System.out.println(valueInLong);*/

String valueInString = "0.0";
BigDecimal valueInDecimal = new BigDecimal(valueInString);
long valueInLong = valueInDecimal.longValue();
System.out.println(valueInLong);

}

}


Exception in thread "main" java.lang.NumberFormatException: For input string: "0.0"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at com.konzern.solution.StringToNumber.main(StringToNumber.java:18)





To find nearestVegetarianRestaurant from totalRestaurants, allLocations, numRestaurants

package com.cfed.amazon;
import java.util.ArrayList;
// IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM
// SOME CLASSES WITHIN A PACKAGE MAY BE RESTRICTED
// DEFINE ANY CLASS AND METHOD NEEDED
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
// CLASS BEGINS, THIS CLASS IS REQUIRED
public class ConsumerfedITSection
{
    // METHOD SIGNATURE BEGINS, THIS METHOD IS REQUIRED
    List<List<Integer>> nearestVegetarianRestaurant(int totalRestaurants,
                                         List<List<Integer>> allLocations,
                                         int numRestaurants)
{
        // WRITE YOUR CODE HERE
     
        Map<Double,List> locationMap = new TreeMap<>();
     
        for(List<Integer> location : allLocations){
            double value = location.get(0)*location.get(0)+location.get(1)*location.get(1);
            locationMap.put(value, location);
        }
     
        int i =0;
     
        List<List<Integer>> nearbyLocationList = new ArrayList<>();
     
        for(Entry<Double, List> entry : locationMap.entrySet()) {
       
        if(i<numRestaurants) {
       
        nearbyLocationList.add(entry.getValue());
        i++;
        }
        }
     
return nearbyLocationList;
     
    }
    // METHOD SIGNATURE ENDS
 
 
    public static void main(String[] args) {

    int totalRest = 3;
   
    fisrtQuiest s = new fisrtQuiest();
   
    /* List<List<Integer>> allLocations = new ArrayList<>();
    List<Integer> list1 = new ArrayList<>();
    list1.add(1);
    list1.add(-3);
allLocations.add(list1);
List<Integer> list2 = new ArrayList<>();
    list2.add(1);
    list2.add(2);
allLocations.add(list2);
List<Integer> list3 = new ArrayList<>();
    list3.add(3);
    list3.add(4);
allLocations.add(list3);*/
   
   
   
        List<List<Integer>> allLocations = new ArrayList<>();
    List<Integer> list1 = new ArrayList<>();
    list1.add(3);
    list1.add(6);
allLocations.add(list1);
List<Integer> list2 = new ArrayList<>();
    list2.add(2);
    list2.add(4);
allLocations.add(list2);
List<Integer> list3 = new ArrayList<>();
    list3.add(5);
    list3.add(3);
allLocations.add(list3);

List<Integer> list4 = new ArrayList<>();
    list4.add(2);
    list4.add(7);
allLocations.add(list4);
   
List<Integer> list5 = new ArrayList<>();
    list5.add(1);
    list5.add(8);
allLocations.add(list5);

List<Integer> list6 = new ArrayList<>();
    list6.add(7);
    list6.add(9);
allLocations.add(list6);
   
   
//s.nearestVegetarianRestaurant(3, allLocations, 2);
System.out.println(s.nearestVegetarianRestaurant(6, allLocations, 3));
   
}
 
 
}


Output



[[2, 4], [5, 3], [3, 6]]




December 21, 2018

Bought a Circle cutter for creating miniatures tools

Circle cutter

Hi

We bought a circle cutter for creating miniature arts, Nice product and worth for price. you can view miniature works on the link

miniature works



Buy Now...... Hurry






Java program to rotate a matrix to 90 degree - amazon interview questions

/**
 * Amazon interview question rotating a matrix to 90 degree
 */
package com.cfed.amazon;

/**
 * @author Konzernties
 *
 */
public class RotateMatrix {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

int ar[][] = new int[3][3];
int val = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
ar[i][j] = ++val;
}
}

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(ar[i][j]+" ");
}
System.out.println();
}

System.out.println(" Rotated 90 degree to left ");

for (int j = 2; j >= 0; j--) {
for (int i = 0; i < 3; i++) {
System.out.print(ar[i][j]+" ");
}
System.out.println();
}
}
}


Output

1 2 3 
4 5 6 
7 8 9 

 Rotated 90 degree to left 

3 6 9 
2 5 8 
1 4 7

Buy a pendrive




Creating a randum number in java with out using java libraries ( Random class in java)

/**
 * To print a random number between 1 to 100
 *
 *
 */
package com.cfed.regionaloffice;

/**
 * @author konzerntechies
 *
 */
public class RandomNumberGenerator {

/**
* @param args
*/
public static void main(String[] args) {

long value = System.currentTimeMillis();
System.out.println(value % 100);

}

}


Output

54

The Girl in the Room 105 has been nominated for Amazon's most popular books of 2018

- from chetan bhagat instagram post



December 20, 2018

Mi Band 3 (Black) 9,526 customer reviews Warranty Details: 1 year

Additional Information
ASINB07HCXQZ4P
Customer Reviews4.1 out of 5 stars   9,525 customer reviews
Best Sellers Rank#6 in Computers & Accessories (See top 100)
Date First Available28 September 2018

Product information

Technical Details
BrandMi
ColourBlack
Item Height12 Millimeters
Item Width47 Millimeters
Screen Size0.78 Inches
Item Weight18.1 g
Product Dimensions1.8 x 4.7 x 1.2 cm
Batteries:1 Lithium ion batteries required. (included)
Item model numberXMSH05HM
Wireless TypeBluetooth
Voltage5 Volts
Lithium Battery Energy Content0.42 Watt Hours
Number of Lithium Ion Cells1
Included Components1 MI Band, 1 Strap, 1 Charging Cable, 1 User Guide


December 19, 2018

Low cost sun glasses - Raymond - free delivery

Low cost sun glasses - Raymond - free delivery


December 18, 2018

Solution for Amazon interview question - Java developer

/**
 * find all element that satisfies
 *
 * square of a = square of b + square of c
 *
 */
package com.cfed.amazon;

public class SampleClass {

public static void main(String[] args) {
// TODO Auto-generated method stub

int ar[] = {1,2,3,4,5};

for(int i=0;i<ar.length;i++) {

for(int j=0;j<ar.length;j++) {

for(int k=0;k<ar.length;k++) {
// System.out.println(i+" -"+j+" - "+k);

int a = ar[i] * ar[i];
int b = ar[j] * ar[j];
int c = ar[k] * ar[k];

if(a==(b+c)) {
System.out.println(a +" = "+ b + " + "+c);
}
}
}
}

}

}

Output

25=9 + 16
25=16 + 9




December 14, 2018

Things you should buy - a power bank with maximum capacity 20000 mah

Things you should buy


Battery drowning in a nightmare for most of the travellers, Travelling is an inevitable part of our day to day life. We must use GPS, internet etc while travelling we cant avoid these apps, as these apps are battery consuming , an alternate power is needed. Either you should buy an additional battery for your phone. No its not an good idea, as the capacity for the battery will be low, you have to switch off and switch on the phone to remove the battery. In case of inbuilt battery its again a big problem.

So i suggest you to buy a power bank having a capacity of atleast 20000mah or above.

Here is a good option. for 1500 rupees

You can buy this through amazon.


Cash on Delivery is available

If you buy alternative with the same capacity you have to spend around 2000 rupees + GST.

December 13, 2018

Pair Sum - Data structure example in java

package com.cfed.datastructures;
/**
 * You have been given an integer array A and a number K. Now, you need to find out whether any two different elements of the array A sum to the number K. Two elements are considered to be different if they lie at different positions in the array. If there exists such a pair of numbers, print "YES" (without quotes), else print "NO" without quotes.

Input Format:

The first line consists of two integers N, denoting the size of array A and K. The next line consists of N space separated integers denoting the elements of the array A.

Output Format:

Print the required answer on a single line.


 * @author  Consumerfed IT Section kozhikode
 *
 */

public class PairSum {

public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 5;
int v = 6;
int[] ar = {1,2,3,4,5};
boolean isFound = false;
for(int i=0;i<n;i++) {
for(int j=i+1;j<n;j++) {

if((ar[i]+ar[j])==v) {
isFound = true;
break;
}

}

}
if(isFound) {
System.out.println("YES");
}else {
System.out.println("NO");
}

}

}


Output

YES

Learning Data Structure is simple !!!

Facebook comments