instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Given a string, write a Python program to find the first non-repeating character in it, without using any built-in Python functions or libraries. input_str = "aaaaabbbbccc"
codefeedback
What is data transformation, how is it used, and provide an implementation for a data transformation algorithm that converts a string into an integer, considering edge cases and handling errors appropriately.
codefeedback
Construct a regular expression to check if a string begins with a given substring and ends with a specific word.
codefeedback
Write a C++ code to find the longest common substring in two strings, but the substring must be at least 5 characters long and contain at least one digit.
codefeedback
Write a Java program to find the largest element in a given array of integers, but you are not allowed to use any built-in functions or libraries for sorting or finding the maximum value.
codefeedback
Generate a 15-digit random number using Python. The number must be prime.
codefeedback
Write a PHP program to find the sum of all prime numbers in an array. Additional Requirements: - The program should have a time complexity of O(n√m), where n is the size of the array and m is the maximum element in the array. - The program should not use any built-in functions or libraries to check if a number is prim...
codefeedback
Create a method in Java to return the largest prime number less than a given number. The method should have a time complexity of O(sqrt(n)), where n is the given number.
codefeedback
Compare the two strings character-by-character and return the number of differences using Java. However, you are not allowed to use any built-in Java methods or libraries for string comparison. Additionally, ensure that your solution has a time complexity of O(n) and a space complexity of O(1), where n is the length of...
codefeedback
Generate a list of the first ten even numbers in reverse order.
codefeedback
Given a string s, write a function to check if the string is a palindrome. The function should ignore any non-alphanumeric characters and should be case insensitive. s = "A man, a plan, a canal: Panama!"
codefeedback
Generate an array with the first 10 prime numbers.
codefeedback
Update the existing HTML structure to add a new div class named "container" inside the body element, and make sure that the container div has a minimum width of 800 pixels. <body> <h1> My First Webpage </h1> </body>
codefeedback
How do you merge two sorted arrays in O(n) time, where n is the total number of elements in both arrays? #Erroneous Code# ```python def merge_arrays(arr1, arr2): merged_array = [] while arr1 or arr2: if arr1[0] < arr2[0]: merged_array.append(arr1.pop(0)) else: merged_arr...
codefeedback
You need to find the largest subset of an array that sums up to a given value. arr = [1, 2, 3, 4, 5], target = 8 The array may contain negative numbers and the target value can be negative as well.
codefeedback
Convert the given binary string to its corresponding decimal number. However, you are not allowed to use any built-in functions or libraries for converting binary to decimal. You must implement your own algorithm to solve the problem.
codefeedback
Implement a variation of Quick sort algorithm called Randomized Quick sort that selects a random pivot element instead of always choosing the last element as the pivot. Compare the performance of Randomized Quick sort with Bubble sort by sorting an array of integers in ascending order.
codefeedback
Create a CSS style to set the background color of a div class "sample" to a random color from a pre-defined list of colors. Additionally, the background color should change every time the page is refreshed or the div is clicked.
codefeedback
Construct an array of objects with the fields "name", "age", and "gender". Each object should also have a nested array called "hobbies" which can contain multiple strings representing the person's hobbies. Additionally, add a method to each object called "introduce" that prints out a string introducing the person's nam...
codefeedback
Summarize the given paragraph in < 100 words, ensuring that the summary includes information about Ada Lovelace's contributions to the field of computer programming and her relationship with Charles Babbage. Additionally, the summary should mention the year in which Lovelace wrote a detailed description of the Analytic...
codefeedback
Write a program that prompts the user to enter their age and then determines and displays their age group based on the following criteria: - If the age is less than 13, display "Child". - If the age is between 13 and 19 (both inclusive), display "Teenager". - If the age is between 20 and 64 (both inclusive), display "A...
codefeedback
Construct a switch statement to log different grades messages based on the grade variable. The grade variable can only contain the following values: "A+", "A", "B", "C", "D", "F". If the grade variable is not one of these values, log an error message.
codefeedback
Given a list of numbers, find the minimum and maximum elements. However, you must do this without using any built-in functions or methods for finding the minimum and maximum.
codefeedback
Write a JavaScript code to print the first 10 terms of the Fibonacci series, but exclude any terms that are divisible by both 3 and 5.
codefeedback
Write a Python function to compute the maximum value for each key in a given dictionary, but only if the value is an integer and divisible by 3. d = {'a': 12, 'b': 20, 'c': 30}
codefeedback
Write a Python program to print the following pattern with the following additional constraints: 1. The number of rows must be an odd number. 2. Each row must have a different number of elements. 3. The pattern must be printed in reverse order for odd-numbered rows. 4. The elements in each row must be printed in ascen...
codefeedback
Write a Python function to create a two-dimensional array of specified dimensions, ensuring that all elements in the array are unique.
codefeedback
Write a Python function to generate the powerset of a given list, where the list may contain duplicate elements. list = [2, 4, 4]
codefeedback
Write a Python function to replace all the occurrences of a given substring with another, but with the following additional constraints: 1. The function should be case-insensitive, meaning it should replace occurrences of the substring regardless of whether they are in uppercase or lowercase. 2. The function should n...
codefeedback
Implement a class hierarchy in Python for a zoo management system. The system should have a base class called "Animal" with the following attributes: name, age, and species. Create derived classes for different types of animals such as "Mammal", "Bird", and "Reptile". Each derived class should have additional attribu...
codefeedback
Write a C++ class to represent a date, including methods to perform various operations and validations on the date. The class should have the following attributes: - Integer variables to store the day, month, and year of the date. The class should have the following methods: 1. A constructor to initialize the date wi...
codefeedback
Describe how to debug a multithreaded C++ program using GDB, with at least three concurrent threads.
codefeedback
Write code in Java to create a circular doubly linked list with the following requirements: 1. Each node in the list should contain an integer value and a reference to the previous and next nodes. 2. The list should have a method to add a new node at the beginning. 3. The list should have a method to add a new node at ...
codefeedback
Name the components of a machine learning pipeline specifically designed for sentiment analysis of social media data, including preprocessing steps, feature extraction techniques, and the algorithms commonly used for classification.
codefeedback
Construct a query in SQL to find the names of the customers who made purchase on a given date and spent more than $100. The table name is 'Orders', the given date is '2020-06-25', and the customer names should be ordered in descending order of their total purchase amount.
codefeedback
Construct a Java program for sorting a given array in ascending order using the Bubble Sort algorithm. #Additional Information# - The Bubble Sort algorithm works by repeatedly swapping adjacent elements if they are in the wrong order. This process is repeated until the array is sorted. - You are required to implement ...
codefeedback
Suggest the best practice for minimizing the risk of SQL injection attacks, while also ensuring optimal database performance.
codefeedback
Describe the steps of creating an application using the Flask framework, including setting up routes, handling forms, and implementing authentication and authorization. Additionally, provide an example of a common error that beginners may encounter when using Flask and explain how to fix it.
codefeedback
Convert the given list to a set while ensuring that the resulting set is sorted in descending order. Additionally, the elements in the set should be unique and greater than 1. Finally, the program should output the sum of all the elements in the set. my_list = [2, 3, 5, 7]
codefeedback
Define a function that takes a list of numbers as input and returns a list of all odd numbers greater than 10 and less than 100.
codefeedback
Multiply each element in the following list with 10, but ensure that the multiplication is performed using recursion instead of iteration. my_list = [2, 4, 6]
codefeedback
Create a pandas dataframe from the following dictionary. The 'Name' column should contain 10,000 unique names randomly generated using a combination of letters. The 'Age' column should contain 10,000 randomly generated ages between 18 and 65.
codefeedback
Compute the result of the following mathematical expression in Python, while also ensuring that the final result is rounded to the nearest whole number. Additionally, you should implement the calculation logic as a recursive function instead of using the built-in arithmetic operators. (4 + 5 * 7 - 9) / 2
codefeedback
Using Python, create a function that takes in an integer n and returns a list containing the first n prime numbers. The function should have a time complexity of O(n^2) or better and should not use any external libraries or functions for prime number generation.
codefeedback
Using Python, create a function to check if a given string contains at least one uppercase letter, one lowercase letter, and one numeric digit. Additionally, the function should return the number of uppercase letters found in the string.
codefeedback
Calculate the sum of all even elements in a given list of positive integers using Python. The list should contain at least 10 elements. Find the sum only if the list has more even elements than odd elements. Otherwise, output "No sum found".
codefeedback
Write a Python function to remove the characters which have odd index values of a given string, while also ignoring any punctuation marks present in the string. The function should return the modified string.
codefeedback
Find the longest palindrome in a given string using Python. The palindrome should consist of at least 3 characters and ignore any whitespace or special characters. Additionally, you are not allowed to use any built-in functions or libraries for string manipulation. string = "My name is John"
codefeedback
Write a Python function to format a specified string to limit the number of characters to 6. The function should also replace any vowels in the string with the corresponding number (e.g. 'a' becomes '1', 'e' becomes '2', 'i' becomes '3', 'o' becomes '4', 'u' becomes '5'). The formatted string should be returned. Examp...
codefeedback
Create a function to convert a given number from decimal to binary representation using Python. The function should not use any built-in functions or libraries for converting decimal to binary.
codefeedback
Modify the following function to return the number of unique elements in a given array, without using any additional data structures such as arrays, hash maps, or sets. int count_unique(int array[], int n) { int count = 0; int i; for (i = 0; i < n; i++) { int j; for (j = 0; j < i; j++...
codefeedback
Implement a Java program for finding the index of the first occurrence of a target element in a sorted array. The array can contain duplicates. Requirements: - The time complexity of your solution should be O(log n), where n is the size of the array. - The space complexity of your solution should be O(1), i.e., it sho...
codefeedback
Write a JavaScript code to eliminate any symbols and numbers from a given string, while preserving the spaces and retaining the order of the remaining characters.
codefeedback
Write a SQL query to join two tables on a specified condition and display only the rows where the sum of the age and marks is greater than 100. Table 1: id name age 1 a 15 2 b 18 3 c 20 Table 2: id class marks 1 10 80 2 10 75 3 11 70 # Erroneous Code Reference # `...
codefeedback
Write a Python program to determine if a given number is an Armstrong number, and print all the Armstrong numbers within a given range.
codefeedback
Create a function to find the total area of a triangle, given its base, height, and the length of its three sides.
codefeedback
Create a Java program to check for a palindrome. In addition to checking for palindromes, the program should also account for special characters, spaces, and letter case. For example, "A man, a plan, a canal: Panama" should be recognized as a palindrome. Write a program that takes a string as input and determines whe...
codefeedback
Improve the following code in order to create a balanced binary search tree. Node insert(int x, Node root) { if (root == NULL) { root = new Node; root->key = x; root->left = root->right = NULL; } else if (x < root->key) { if (root->left == NULL) { Node new...
codefeedback
Edit the following function so that it counts the prime numbers in the given array. arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
codefeedback
Design a PHP code snippet to create a scientific calculator that includes advanced mathematical functions such as exponential calculations, logarithms, trigonometric functions, and complex number operations.
codefeedback
Create a function in Python that prints out a stringified version of a list of integers, where each integer is squared and converted to hexadecimal.
codefeedback
Create a function to check if a specific item is present in a list of integers. The function should return the index of the item if it exists in the list and -1 otherwise. Additionally, the function should have a time complexity of O(log n), where n is the length of the list.
codefeedback
Implement a function that takes two integers and returns the smaller one. However, you are not allowed to use any comparison operators (e.g., <, >, <=, >=) or conditional statements (e.g., if-else, switch-case) in your solution.
codefeedback
How can you get the length of a list in Python, without using the built-in len() function or the len() method of the list object?
codefeedback
Write a function in Python to calculate the value of "e" to 4 decimal places, without using any built-in math functions or libraries.
codefeedback
Write a MySQL query to find the highest salary of each department, but exclude departments with less than 5 employees.
codefeedback
Given a number, create a function that returns a list that contains all its divisors in ascending order, excluding 1 and the number itself. The function should handle numbers up to 10^9 and return an empty list if the number is prime. num = 987654321
codefeedback
Write a Python code to calculate the sum of natural numbers up to n, but without using any loops or recursion.
codefeedback
Describe the details of the try-except statement in Python. Additionally, you must implement a function that takes a list of integers as input and uses a try-except statement to calculate the sum of the list. If any of the elements in the list are non-integer values, the function should raise a custom exception called ...
codefeedback
Write an SQL query to find the third highest salary of an employee in a given department.
codefeedback
Write a JavaScript code to check if a string is a valid email address, while also verifying the domain name and top-level domain (TLD) format. A valid email address should meet the following conditions: 1. It must have a username part before the "@" symbol. 2. The username part can contain only alphanumeric characters...
codefeedback
Increase the difficulty of the given programming test question by adding additional requirements and constraints: Rewrite the given JavaScript code in Python, without using any built-in array manipulation methods (such as map, filter, or reduce). Input: - An array of integers. Output: - A new array where each elemen...
codefeedback
Create a SQL query to calculate the count of each type of book in a library, where each book has multiple authors. Input: - A table called "Books" with the following columns: - book_id (integer) - title (string) - genre (string) - author_id (integer) Output: - A table called "Book_Counts" with the following c...
codefeedback
Construct a query in PostgreSQL to find the names and emails of all users who have "google.com" in their emails and whose names start with a vowel.
codefeedback
Write the SQL query to delete all records from the table 'Customer' where the 'registration_date' is more than 1 year ago.
codefeedback
Create a function in Python to evaluate if a given number is prime and has exactly two distinct prime factors.
codefeedback
Write a code to find the maximum subarray sum in an array using dynamic programming, but with the additional requirement that the solution must have a time complexity of O(n).
codefeedback
Create a function in Java to find the largest prime number within a given range.
codefeedback
Calculate the sum of the prime numbers in the array [2, 3, 5, 7, 10]
codefeedback
Write a SQL query to find out the maximum salary earned by an employee in a specific department, considering only employees with a tenure of at least 2 years.
codefeedback
Create a program in JavaScript to check if two strings are anagrams. Additionally, implement a function to remove all duplicates from a string before checking if it is an anagram.
codefeedback
Design a class Car with a constructor to initialize the variables _type, _year and _color. The _type variable should only accept values from a pre-defined list of valid car types. The _year variable should only accept values within a specified range of valid car years. The _color variable should only accept values from...
codefeedback
Parse the following JSON and extract the value of the variable 'price'. However, you are not allowed to use any built-in JSON parsing functions or libraries.
codefeedback
Write a code to implement Selection Sort in Java with the following additional constraints and requirements: - The code must be implemented using recursion instead of iteration. - The input array must contain at least 10 elements. - The code must be written using object-oriented programming principles. - The code shoul...
codefeedback
Design a function to remove duplicates from an unsorted array of integers in-place. The function should have a time complexity of O(n), where n is the number of elements in the array. The function should also remove all occurrences of duplicates, not just one occurrence.
codefeedback
Write a C++ code to find the greatest common divisor of two integers, but without using any loops or recursion.
codefeedback
Given a list of strings, write a program to sort the strings in alphabetical order. Additionally, you need to ignore the case sensitivity while sorting the strings. lst = ["apple", "Orange", "grapes"]
codefeedback
Calculate the median of a list of numbers. lst = [1, 2, 3, 4, 5]
codefeedback
Create an algorithm to sort a list of numbers in ascending order, ensuring that the algorithm has a time complexity of O(n log n). Additionally, the algorithm should handle duplicate numbers within the list and ensure their relative order is preserved. The list to be sorted is lst = [2, 5, 1, 7, 4].
codefeedback
Create a program to generate a doubly linked list where each node contains both a forward and backward pointer.
codefeedback
Given a list of dictionaries, each containing a key "price" with a positive integer value, implement a function to calculate the sum of all the prices and return the result as an integer. Example: Input: [{"price": 5}, {"price": 7}, {"price": 9}] Output: 21 Note: - The list can contain any number of dictionaries. - ...
codefeedback
Given the following object, write a function in JavaScript to count the occurrences of each character in the object's values. The function should also remove any duplicate characters from the count. obj = { "name": "John Doe" } Example: Input: obj Output: {'n': 2, 'a': 1, 'm': 1, 'e': 1, 'J': 1, 'o': 1, 'h': 1, 'D':...
codefeedback
Write a function in JavaScript that takes an integer n and returns the nth Fibonacci number. However, you are not allowed to use recursion or the built-in Fibonacci formula to calculate the number.
codefeedback
Write a Java program that takes two strings as inputs and checks if one string is a rotation of the other. The program should handle cases where the strings contain duplicate characters and whitespace. Additionally, the program should not use any built-in string manipulation functions or methods.
codefeedback
Given a string and a set of delimiters, write a function in JavaScript to split the string. The function should only split the string at the delimiters if they are followed by a space. The delimiters should not be included in the resulting array. Additionally, the function should remove any leading or trailing whitespa...
codefeedback
Write a function in Python that takes a string and a set of characters as inputs and removes all characters in the string that are in the set. Additionally, the function should ignore case sensitivity while removing characters and return the modified string. The function should also handle the scenario where the input ...
codefeedback
Given the following array of dictionaries, write a function in Python to find and return the longest common prefix in the keys of dictionaries. The longest common prefix should be case-sensitive and should only consider alphabetic characters. If there is no common prefix, return an empty string. arr_of_dictionaries = ...
codefeedback
Write a function in Java that takes a string consisting of brackets and output true if the brackets are properly nested, else output false. The string may also contain other characters, such as letters or numbers, which should be ignored when determining the correctness of the brackets. Additionally, the function shoul...
codefeedback
Find the power of a number using an iterative approach in Java, without using any built-in mathematical functions or operators. The function should be able to handle both positive and negative exponents. Additionally, optimize the solution to have a time complexity of O(log n).
codefeedback
Create a code that sorts elements in an array in descending order.
codefeedback